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
Community
  • 1
  • 1
John Riselvato
  • 12,854
  • 5
  • 62
  • 89

1 Answers1

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>
Offbeatmammal
  • 7,970
  • 2
  • 33
  • 52
  • 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. – John Riselvato Feb 11 '13 at 23:48
  • 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) – Offbeatmammal Feb 12 '13 at 03:14
  • 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? – Offbeatmammal Feb 12 '13 at 03:20
  • 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. – John Riselvato Feb 12 '13 at 15:39