View Full Version : detect select option changes

10-24-2009, 03:53 PM
Hi all,i'm wondering how to detect select option changes.For example i want the data in database changed when i click on update button and there are changes on the select option side.If the values on the select option are not changed,i can't update the data..Is there a way to achieve it?Thanks a lot...

10-24-2009, 05:19 PM
Since you're in the javascript section here, the simplest thing would be:

<select name="whatever" onchange="doSomething();">
<option value="">Hi</option>
<option value="">There</option>
<option value="">Folks</option>
<option value="">!</option>

What you do with doSomething(); though is up to you, it need not even be a function. You may elect to simply put script code directly into the event. For a real time update to the database without submitting the form though, you will need some sort of AJAX associated with this event.

However, when the form is submitted (if you are willing to wait for that), if the select has a name, its value (changed or not) will be available to PHP (or whatever server side language you are using) as post or get data. If you knew its value before, you would be able to tell on the server side if it had been changed or not and act accordingly.