justuptime.com - monitor your servers & websites

form submission with Javascript

You are viewing this site as a guest. Join our community to get your questions answered and share knowledge. Active members may advertise and ask for a website critique.

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!

andy206uk's picture
DeveloperModerator

He has: 1,754 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!)

Andyk

Blog of a Web Designer
Give a man a fish and you feed him for a day. Teach him to use the Net and he won't bother you for weeks.