SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    malaysia
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    <Help>About <select multiple>!</Help>

    here is my code:
    <select name="sltprint" size="10" maxlength="10" multiple>
    <option>Peter</option>
    <option>Eric</option>
    <option>Mary</option>
    <option>Mice</option>
    <option>Frank</option>
    <option>Alex</option>
    </select>

    If I select a lot of fields, for example: Peter,Mary,Alex and Frank. How can I get the value?
    If I use formA.sltprint.value, It will return Peter only. How can I get the other fields? I mean, Mary,Alex and Frank.

    Thank you!

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You would need to loop through all of the options to find the values of the selected ones.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    malaysia
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, I not understand.. How to loop? How to write the code?

  4. #4
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    var sel = document.form1.sltprint;
    for(var i=0;i<sel.options.length;i++) {
      if(sel.options[i].selected == true) {
        alert(sel.options[i].value);
      }
    }
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


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
  •