form submission with Javascript

They have: 53 posts

Joined: Oct 2005

Hello!
I am searching over the net for quite a long, but I have almost no idea concerning Javascript so I can't figure out the solution to my problem...
I have a form that show a drop-down menu, which takes all its values through a Mysql database via PHP. What I want to do is to submit the form to the next page (from index.php ---> retrieve_data.php) without the need of a "Submit" button.
When the user selects one of the given options, automatically he will be redirected to retrieve_data.php?id=5 for example...

Thank you in advance!

He has: 1,758 posts

Joined: Jul 2002

I think this will do what you need:

<form method="get" action="whatever.php">

<select name="name" onchange="javascript:this.form.submit();">
  <option value="value">name</option>
  <option value="value"> name </option>
  <option value="value"> name </option>
  <option value="value"> name </option>
  <option value="value"> name </option>
</select>

<noscript><input type="submit" value="go!"></noscript>

</form>
'

just add onchange="javascript:this.form.submit();" to your select box. (be sure to put a submit button in the tags though, incase javascript is disabled!)

Andy

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.