SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript Drop Down Values

    Hi I'm trying to display value of drop down list on a page without having to reload the page. So the user selects a weight and it just prints that on screen. What would be the best way of doing this?

    Code so far

    Code:
    <select id="weighta" >
    	<option selected="selected">Weight</option>
    	<option value="1">1</option>
    	<option value="2">2</option>
    	<option value="3">3</option>
    	<option value="4">4</option>
    	<option value="5">5</option>
    </select>
    
    <script type="text/javascript">
    		document.write(document.getElementById('weighta').value);
    </script>
    Thanks

  2. #2
    SitePoint Enthusiast PicklePete's Avatar
    Join Date
    Apr 2008
    Location
    England
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey, try this:

    Code:
    function printWeight() {
    	var weight = document.scales.weight[document.scales.weight.selectedIndex].value;
    	document.getElementById('printOut').innerHTML = "My weight is... " + weight + "kg!";
    }
    HTML Code:
    <p id="printOut">My weight is... nothing yet!</p>
            <form name="scales">
                <select name="weight" onchange="printWeight();">
                    <option value="50">50kg</option>
                    <option value="60">60kg</option>
                    <option value="70">70kg</option>
                    <option value="80">80kg</option>
                    <option value="90">90kg</option>
                    <option value="100">100kg</option>
                </select>
            </form>

  3. #3
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey, that works! Many thanks.
    Last edited by pkg123; Jun 20, 2008 at 07:24.


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
  •