Results 1 to 3 of 3

Thread: How to pass select option value to a function

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Windsor
    Posts
    100

    How to pass select option value to a function

    I am using Select and JavaScript. When a user selects any value, I like to pass that value to JavaScript function but I cannot pass it. I can pass any value for input value. Is there any way that I can pass any value to a function, when user selects any option? Please see my sample select and function.

    <select name=sTermPref <%=Trim(RSCHECK("sTermPref"))%> size="1" onChange = "getInfo()">
    <option selected> <%if RSCHECK("sTermPref") <> "" then response.write RSCHECK("sTermPref") %>
    </option>
    <option>Variable</option>
    <option>6 Month Closed</option>
    <option>6 Month Convertible</option>
    <option>6 Month Open</option>
    <option>1 Year Closed</option>
    <option>1 Year Convertible</option>
    <option>1 Year Open</option>
    <option>2 Year Closed</option>
    <option>3 Year Closed</option>
    <option>4 Year Closed</option>
    <option>5 Year Closed</option>
    <option>7 Year Closed</option>
    <option>10 Year Closed</option>
    </select>


    <SCRIPT language="JavaScript">

    function getInfo() {

    alert document.forms[0].sTermPref.value ;

    }

    </SCRIPT>

  2. #2
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    Something like this?

    Code:
    <script type="text/javascript"><!--
      function showOption(option) {
        alert(option);
      }
    //--></script>
    <select onchange="showOption(this.options[this.options.selectedIndex].value);">
      <option value="Option 1">Option 1</option>
      <option value="Option 2">Option 2</option>
      <option value="Option 3">Option 3</option>
      <option value="Option 4">Option 4</option>
    </select>

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Windsor
    Posts
    100
    Hi Rick

    Thank you very much. You save me a lot of time

    Naci

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width