Results 1 to 2 of 2

Thread: detect select option changes

  1. #1
    Join Date
    Sep 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default detect select option changes

    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...

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Since you're in the javascript section here, the simplest thing would be:

    Code:
    <select name="whatever" onchange="doSomething();">
    <option value="">Hi</option>
    <option value="">There</option>
    <option value="">Folks</option>
    <option value="">!</option>
    </select>
    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •