SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2006
    Location
    London
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Interrogating/validating select box values.

    I have a new query, sorry!

    How do I access the values of a drop down field/select box to determine which items have been selected?

    The select box values are generated by an external .js file which would appear to mean that using..

    var bloname = document.forms["requisition"].elements["blo_name"];
    var selectedBlo = bloname.value;

    doesn't work?

    I need to validate that something has been picked and also to grab one of the values to be able to create a 'sendto' email address once the form is completed.

    Apologies for the newbie type question but I'm learning and it's a bit of a steep climb!

  2. #2
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Select elements have a selectedIndex property and an options array that can be used to get the selected value (if the select box is not a "multiple" select box). For example:

    var selectedBlo = (bloname.selectedIndex < 0 ? null : bloname.options[selectedIndex]);


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
  •