javascript function to pass a list element to an asp variable

hello,
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)">
                  <option>1</option>
                  <option>2</option>
                  <option>3</option>
                </select>
bassfaldoAsked:
Who is Participating?
 
jra73Commented:
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">
    <option>1</option>
    <option>2</option>
    <option>3</option>
  </select>
  <input type="submit" name="submit" value="Submit">
</form>


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

<%@ page language="java" %>
<%
var tmp = request.getParameter("tmpLevel")
%>
<html>
  <head><title>myasp.asp</title>
  </head>
  <body> You selected <%=tmp%>
  </body>
</html>

Hope this helps!
0
 
nayernaguibCommented:
Try this code segment:

____________________________________________

<select name="tmpLevel" onChange="javascript:setlev(tmpLevel[tmpLevel.selectedIndex].text)">
                  <option>1</option>
                  <option>2</option>
                  <option>3</option>
                </select>

____________________________________________

__________________

  Nayer Nabil
0
 
bassfaldoAuthor Commented:
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?

bassfaldo
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.