SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: onChange event

  1. #1
    SitePoint Guru TacMaf's Avatar
    Join Date
    Dec 2005
    Location
    Manchester, United Kingdom
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    onChange event

    Hi, I have a problem that I have googled to death and can't find the answer.

    So I have a form with a <select> field. I don't know much about onChange, but I want to update another select field with info from the database.

    Hard to explain:
    PHP Code:
    <form action="" method="post">
    <
    table align=center width="100%" bgcolor=#5e5e5e border=1 cellpadding=2 cellspacing=0>
    <tr><td colspan=2 background="tablebg.jpg" align=center><font face=verdana color=white size=2>Disable a Feature</td></tr>
    <
    tr>
    <
    td width=25%><font face=verdana size=1>Feature:</td><td>
    <
    select name="feature" id="feature" style="width: 100%; background: #333333; font-family: Verdana; color: white; font-size: 11px;">
                    <
    option selected>Login</option>
                    <
    option>Register</option>
    </
    select></td></tr>
    /* When a user selects a field I want the next select field to check the database and update accordingly */
    <select>Check database for "feature" and choose correct select statement </select>
    <
    tr><td colspan=2 align=center><input style="width: 25%; background: #333333; font-family: Verdana; color: white; font-size: 11px;" type="submit" name="disable"  value="Disable"></td></tr>
    </
    table>
    </
    form
    I could do this in PHP but it would have to reload the page. Could anyone help?

    Thanks.

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,423
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    You'll need to use Ajax. That's exactly the kind of stuff it is meant for.

  3. #3
    SitePoint Guru TacMaf's Avatar
    Join Date
    Dec 2005
    Location
    Manchester, United Kingdom
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. Do you know any good examples or tutorials for ajax in this case?

  4. #4
    SitePoint Addict Wildhoney's Avatar
    Join Date
    Apr 2006
    Location
    Nottingham
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've always liked Tizag's tutorials:
    http://www.tizag.com/ajaxTutorial/
    TalkPHP.com - The Friendly PHP Community

    Watch Reaper Online - Watch Chuck Online

  5. #5
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Do it in PHP first, so it will work with JavaScript turned off. Then add the JavaScript functionality to use ajax for those who have it enabled.

  6. #6
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    To be honest, people without JavaScript (daft as they are) won't be able to use this feature at all, without a submit button.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  7. #7
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    true, should put one of them in as well then

  8. #8
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yup, you need ajax


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
  •