1

From my understanding, once a form is being submitted, you cannot add parameters to it by adding extra inputs (at least this [link] is what gave me that assumption)

For example:

var form = $('form');
form.submit(function(e) { 
 searchForm.append(
   '<input name="a" type="hidden" value="' + a + '">' +
   '<input name="b" type="hidden" value="' + b + '">' );
}

So my next guess would be to dynamically add parameters via location. I followed this code but that refreshes the page and only works with adding one parameter, and gets ride of my original input on the form. This doesn't work.

Maybe what I am trying to do isn't possible with a get but only with a post. Which I don't want to use a post. but to clear things up, as a user I search for a location, when the person submits the search, jquery interferes with submit() and does look on the address to find a lat/lng. If a lat and lng exists I want to pass the lat and lng along with the searched address to the next page via get.

Example:

website.com/path?search=NC&a=35.38905&b=-78.486328

1 Answer 1

2

try this (works on a GET, not tried a POST)

<script type="text/javascript">
$(document).ready(function(){
  $("#fx").submit(function(event){
  //  event.preventDefault();
    var newitem = document.createElement("input"); 
        newitem.name = "addedItem";
        newitem.type = "text";
        newitem.value = "As if by magic";
        $("#fx").append(newitem);

  });
});
</script>

<form id="fx" name="fx">
    <input type="text" name="bob">
    <input type="submit">
</form>
Sign up to request clarification or add additional context in comments.

4 Comments

Your example is the same as my appending the code. Unfortunately, i figured it didn't hurt to try but this doesn't work as well.
In Chrome this is working fine, it adds the new value pair to the form. Is the problem a browser specific one (I'll have a look in others)
Update: just tried same code in IE, Safari and Chrome and works fine adding new values to the request... what browser is failing for you?
It looks like you can't set a new document element from an ajax call. So... your code is correct, outside of getJSON... I guess i should post a new question.

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.