0

I have three inputs in the following form. Two inputs type is text and another one input type is hidden. Now when I click the submit button then two input values need to set the hidden input before run the ajax query. Because, ajax will get the data from the hidden input only. I have tried it myself but, it's not working for me. Now, when I click the submit ajax working first then set the both values to hidden input.

<form>
<input type="text" class="date" value="2018-11-09">
<input type="text" class="time" value="15:00:00">
<input type="hidden" class="date-time" value="">
<button type="button" class="button">Submit</button>
</form>
2
  • 2
    Show us what you have tried that did not work. Also show us the logic that is doing the ajax. Commented Sep 19, 2018 at 17:11
  • $('.date-time').val(whatever_value_you_want); if you make sure to have a logic around that before calling your AJAX function, you will set the value of the hidden input field. Now, without further information and code it will be impossible to help you any further as we have absolutely zero clue about your application. Commented Sep 19, 2018 at 17:29

1 Answer 1

1

For the following code I am assuming that the 'Submit' button has its type changed to 'submit' as this will give you more control of when the form is submitted:

$('form').submit(function(event) {

  event.preventDefault(); // stop the form from automatically submitting

  $('.date-time').val($('.date').val() + $('.time').val());

  console.log($('input[type=hidden').val());

  // call your ajax here

});

The important line here for your question is:

  $('.date-time').val($('.date').val() + $('.time').val());

This sets the value of the input .date-time to the input of .date and .time, although I would recommend using ids instead of classes as they are unique

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.