javascript function to pass a list element to an asp variable

Posted on 2005-04-11
Last Modified: 2010-04-17
how can I get a list element from a <select> list to be assigned to an asp variable?

this is what I've come up with but it doesn't work...

var lev=1; //global variable initialised to 1

function setlev(tmp)
              lev = tmp;


 <select name="tmpLevel" onChange="javascript:setlev(this)">
Question by:bassfaldo
    LVL 14

    Expert Comment

    Try this code segment:


    <select name="tmpLevel" onChange="javascript:setlev(tmpLevel[tmpLevel.selectedIndex].text)">



      Nayer Nabil

    Author Comment

    Hello Nayer,
    thanks for the code, but unfortunately I get same result, the selected value is not assigned to the lev variable, and I keep getting an error in the setlev function. Amazingly this happens even if I make setlev an empty function. Any ideas?

    LVL 1

    Accepted Solution

    You cannot call your asp function directly from the html page. You will have to get the value when the user submits the form.

    For Example:

    <form action="myasp.asp" method="post">
      <select name="tmpLevel">
      <input type="submit" name="submit" value="Submit">

    myasp.asp might look something like this if you were using JSP:

    <%@ page language="java" %>
    var tmp = request.getParameter("tmpLevel")
      <body> You selected <%=tmp%>

    Hope this helps!

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
    This article will show, step by step, how to integrate R code into a R Sweave document
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now