• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

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>
0
bassfaldo
Asked:
bassfaldo
1 Solution
 
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
 
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now