SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Jul 2004
    Location
    Jed.
    Posts
    245
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Read Selection options and reprint

    Hello,

    How can I read the Options of the following list and then reprint




    Code:
      <select name="mylist">
        <option value="AP">
          Apple
        </option>
    
        <option value="AR">
          Apricot
        </option>
    
        <option value="BA">
          Banana
        </option>
      </select>
    Code:
    "AP"=>"Apple",
    "AR"=>"Apricot",
    "BA"=>"Banana",

  2. #2
    SitePoint Member
    Join Date
    Jan 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try to translate the code web site

  3. #3
    SitePoint Addict
    Join Date
    Jul 2004
    Location
    Jed.
    Posts
    245
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't understand!!

  4. #4
    SitePoint Addict bronze trophy AllanP's Avatar
    Join Date
    Sep 2010
    Location
    Australia
    Posts
    298
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    This works. The result is an alert() which gives the name of the fruit and the value of the option. You can modify the output to meet your needs.

    Code :
    <!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
     
    <head>
     
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Select a Fruit</title>
    <script type="text/javascript">
    <!--
     function mySelection(obj)
      {// check for invalid selection
        if(obj.selectedIndex=="0"){ return; }
       // ---------  
        var optionText=obj.options[obj.selectedIndex].text;
        var optionValue=obj.options[obj.selectedIndex].value;
     
        alert("You have selected "+optionText+" with a value of "+optionValue+"")
      }
    //-->
    </script>
    </head>
     
    <body>
     
    <p><select name="mylist" onchange="mySelection(this)">
    <option value="0">Select a fruit ..</option>
    <option value="AP">Apple</option>
    <option value="AR">Apricot</option>
    <option value="BA">Banana</option>
    </select></p>
     
    </body>
     
    </html>


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
  •