0

This is the form:

<form role="form" action="<?php echo $action; ?>" name="send_request" method="post" onsubmit="calcDist();" id="send_request">
  <div class="content">
    <div class="form-group">
      <input type="text" id="input-from" class="form-control" name="from" placeholder="<?php echo $entry_from; ?>" />
      <input type="text" id="input-to" class="form-control" name="to" placeholder="<?php echo $entry_to; ?>" />
      <input type="hidden" class="form-control" name="kmdist" value="">
    </div>
    <input type="submit" value="<?php echo $button_send; ?>" class="btn btn-default" />
  </div>
</form>

I'm computing the distance in calcDist(); between the given cities from the text inputs on submit and save the cities to the database through the form action, but I don't know how to add that distance variable to the post data array before the actual saving action.

1
  • Do not use enctype="multipart/form-data" when not uploading files. Commented Feb 26, 2015 at 21:54

1 Answer 1

1

Just set the value of the hidden field kmdist in calcDist():

HTML:

<input type="hidden" class="form-control" name="kmdist" id="kmdist" value="">

Javascript:

document.getElementById('kmdist').value = calculatedDistance;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I've tried, but it's not in the post array.

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.