3

I have some javascript that submits to an HTML form in my app upon a "click" event like so....

google.maps.event.addListener(marker, 'click', function() {
  $('form').submit()
});

However I want to change the data before I send it. Is this possible? I don't want to use Ajax $.post if I can help it. I just want to change what the form sends to my Rails controller before submit.

Thanks!

1
  • Sure, just update the field values before calling ".submit()". Commented Nov 26, 2011 at 18:58

2 Answers 2

6

If you already have a field with name="search" you can change it's value like so:

google.maps.event.addListener(marker, 'click', function() {

   $('form input[name="search"]').val( place.name );
  $('form').submit()
});

Or if not:

google.maps.event.addListener(marker, 'click', function() {

  $('form').append('<input type="hidden" name="search" value="'+place.name+'" />').submit()
});

Assuming place.name is known like in your previous question.

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

Comments

1

You can update the value of specific fields by id before you call submit:

$("form #fieldID").val("Value you want to change");

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.