Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
  1. #1
    Senior Member
    Join Date
    Mar 2002
    Location
    Alabama sans the damn flag
    Posts
    263
    Member #
    38
    Code:
    <Form name='DrugBrand' action='#'>
    <input type=button onClick='choose()' name='DrugBrandButton' value='Return Drug Name'></input><BR>
    <SELECT Name='DrugSelect' size=25 onClick='choose()'>
    <option>1 Plus 1 F</option>
    ...
    ...
    </form></td></tr></table>
    ...
    ...
    
    <SCRIPT Language="JavaScript">
    function choose(  )
    {
        var val = document.DrugBrand.DrugSelect;
    alert("Chosen date is " + val.value);
    
    .....
    the above code represents the page I'm currently working on. The formname is DrugBrand, the select list is DrugSelect and I'm trying to get the selected value.

    the alert tells me that val is an object, but I get a blank when ask for value (val as opposed to val.value)

    anything obviously stupid that I'm doing wrong? I know I'm close.
    DerFarm
    I talk to squirrels.
    Squirrels Answer.

  2.  

  3. #2
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    It looks fine to me. Try using something like:
    Code:
    function foo() // maybe choose is reserved
    {
        alert("Chosen date is " + document.DrugBand.DrugSelect.value);
    }
    And for the daring:
    Code:
    <select ... onChange="alert(this.value)" ...>
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  4. #3
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Try this:
    Code:
    <form name='DrugBrand' action='#'>
        <input
            type="button"
            name="DrugBrandButton"
            value='Return Drug Name' /><br>
        <select name="DrugSelect" size="25" onchange="choose(this)">
            <option value="number 1">1 Plus 1 F</option>
        </select>
    </form>
    <script language="JavaScript">
        function choose(list) {
            var val = list.item[list.selectedIndex].value
            alert("Chosen date is " + val);
        }
    </script>

  5. #4
    Senior Member
    Join Date
    Mar 2002
    Location
    Alabama sans the damn flag
    Posts
    263
    Member #
    38
    Thanks, but the real answer was REALLY stupid. I don't have any values ... only text.


    var val = list.item[list.selectedIndex].TEXT
    DerFarm
    I talk to squirrels.
    Squirrels Answer.

  6. #5
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Yeah, that would return the text alright! :-P


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:39 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com