SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Mar 2002
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Drop Down Menu - OnChange

    Hello everyone,

    I am having problems and would greatly appreciate your help -

    I would like to know how I am able to do this without the use of a "submit" button - ie onchange.

    Here is what I am working with.


    <form name="form1" method="post" action="">
    <select name="MyNumber">
    <option value="One">One</option>
    <option value="Two">Two</option>
    <option value="Three">Three</option>
    <option value="Four">Four</option>
    <option value="Five">Five</option>
    </select>
    <input type="submit" name="Submit" value="Submit">
    </form>

    <?php

    @print ($MyNumber);

    ?>

    Thank you in Advance.
    Sometimes I get all confused !

  2. #2
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can't do it with php (an onChange event that is) if you're not going to reload the page.

    so you want to write out the value of the drop down menu each time someone changes it? that can all be done with javascript. before i post code, please confirm or elaborate on what you're trying to do.

  3. #3
    SitePoint Member
    Join Date
    Mar 2002
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello makeda,

    I have changed the code a bit (Adding an <option Selected>Choose a number - see below.

    I would like the drop down menu to "onselecting" an option to reload the same page, rewirte the menu and have the users selected option appear as the "selected option" in the list instead of the "<option Selected>Choose a number " text to appear. I want to get rid of the submit button and use Onchange to reload the page.

    eg- If option four is selected the page automatically reloads - then the drop down menu is rewritten and the current selected option is now option four.

    Hope that makes sense,
    Thanks,
    BigA

    <form name="form1" method="post" action="new.php">
    <select name="MyNumber">
    <option selected>Choose a number
    <option value="One">One</option>
    <option value="Two">Two</option>
    <option value="Three">Three</option>
    <option value="Four">Four</option>
    <option value="Five">Five</option>
    </select>
    <input type="submit" name="Submit" value="Submit">
    </form>
    Sometimes I get all confused !

  4. #4
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It makes sense but why not just update your page client side? Is it database driven?

    What you can do is write a function attatched to the onChange event for your page. Basically, all the function will do will be to submit your page:


    frmYourForm.method = "whatever";
    frmYourForm.action = "whatever.php";
    frmYourForm.submit();

    Then, server side on your action page, pull your values out of the querystring and do whatever you want.

    I would write an onLoad javascript function that sets the dropdown menu to the one last selected:

    frmYourForm.ddYourDropdown.value = <?=$MyNumber?>;


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
  •