SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    Atlanta
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to pass the value from select box to the java script

    "Hi,

    how can I pass the value from the drop down menu to the javascript function, I'm using the onChange event.

    Like: <select name = name onChange="selectName()">"
    Aneal

  2. #2
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,121
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    <select name="jump" onchange="runThere(this.form.jump.options[this.form.jump.selectedIndex].value)" size="1">
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2000
    Location
    Yeppoon, Australia
    Posts
    186
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is a good tutorial on this type of thing:
    http://wsabstract.com/javatutors/combos3.shtml
    Knowledge is knowing that a tomatoe is a fruit; wisdom is not putting it in a fruit salad.

  4. #4
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,121
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Good tutorial, too bad it isn't precisely defining the index value.

    this.form.jump.selectedIndex (or this.selectedIndex) is necessary to absolutely define the 0-index of the element which is defined.
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    Atlanta
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    I have done something like this:

    function selectCampus(campus)
    {
    var selection;
    camp = eval(campus);
    if (selection == campus)
    {
    document.location="<?echo $PHP_SELF; ?>?campus=<?echo $campus; ?>";
    }
    else
    {
    alert("Please make your selection");
    }
    }

    //Form Starts here
    <form action = fac_dept_page.php3 method=post>
    <?
    $sql = "select * from class c, fac f where c.faculty_id = f.faculty_id";
    $result = mysql_query($sql);
    if (!$result)
    {
    echo "Not able to connect to the database";
    }
    while ($row = mysql_fetch_array($result))
    {
    //Create multim-dimensional array to hold all results
    $data[] = array("lname" => $row["lname"],
    "fname" => $row["fname"],
    "campus" => $row["campus"],
    "dept" => $row["dept"],
    "cname" => $row["cname"]);
    }
    ?>
    <center><select name="campus" onChange="selectCampus(<?echo $row["campus"]; ?>)">
    <?
    //Loop through $data array and grab all campus and put them in a drop down list
    while(list($key, $val) = each($data))
    {
    ?>
    <option value="<?echo $data[$key]["campus"]; ?>"><?echo $data[$key]["campus"]; ?></option>
    <?
    }
    //Reset array
    reset($data);
    ?>
    </select></center><br>
    Aneal

  6. #6
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,121
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    ugh @ php...

    sorry, give me the output and I can fix it for you (if it isn't working). I don't do php...

    one problem I CAN see is that you do:

    var selection;
    camp = eval(campus);
    if (selection == campus)

    you haven't put any value into selection... it's NULL... So you're trying to see if campus is null with this function.
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright


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
  •