how to pass a javascript variable into asp variable?
-
hai i am an asp programmer. i have two combo boxes optone and opttwo. i have loaded values for optone from database selected <% sqlPRO = "Select field1 From tablename" set rs= conn.Execute(sqlPRO) i=1 do while Not rs.EOF %> <%=rs("field1")%> <% i=i+1 rs.MoveNext loop rs.Close %> now i want to load a value for the second combobox opttwo it's dependant on the first combobox optone function setOptions(chosen) { var selbox = document.frm.opttwo; selbox.options.length = 0; selbox.options[selbox.options.length] = new Option('Select','oneone'); <% strSQLQry = "Select field1 From tablename where ID='" & chosen & "'" rs.Open strSQLQry, conn rs.MoveFirst While Not rs.EOF %> valFromList = "<%=rs("field1")%>"; selbox.options[selbox.options.length] = new Option(valFromList,'oneone'); <% rs.MoveNext Wend rs.Close %> } this code shows an error.i can't get the javascript variable into asp. if anyone known please help me Thanks and Regards Ganesh Mohan
-
hai i am an asp programmer. i have two combo boxes optone and opttwo. i have loaded values for optone from database selected <% sqlPRO = "Select field1 From tablename" set rs= conn.Execute(sqlPRO) i=1 do while Not rs.EOF %> <%=rs("field1")%> <% i=i+1 rs.MoveNext loop rs.Close %> now i want to load a value for the second combobox opttwo it's dependant on the first combobox optone function setOptions(chosen) { var selbox = document.frm.opttwo; selbox.options.length = 0; selbox.options[selbox.options.length] = new Option('Select','oneone'); <% strSQLQry = "Select field1 From tablename where ID='" & chosen & "'" rs.Open strSQLQry, conn rs.MoveFirst While Not rs.EOF %> valFromList = "<%=rs("field1")%>"; selbox.options[selbox.options.length] = new Option(valFromList,'oneone'); <% rs.MoveNext Wend rs.Close %> } this code shows an error.i can't get the javascript variable into asp. if anyone known please help me Thanks and Regards Ganesh Mohan
The problem is that the code is not at all executed in the order that you think it is. All ASP code is executed on the server, then the page is sent to the browser, and the client code is executed. The ASP code that you have put inside your javascript function is always executed when the page is created, not when the javascript function runs. To run server code that uses values from the client code, you have to send another request to the server and send the values along in the request. You can send values either in querystring or in form data. To populate a second select box depending on the first, you can either reload the page to do the request to the server, or do the request behind the scenes using techniques like AJAX.
--- single minded; short sighted; long gone;
-
The problem is that the code is not at all executed in the order that you think it is. All ASP code is executed on the server, then the page is sent to the browser, and the client code is executed. The ASP code that you have put inside your javascript function is always executed when the page is created, not when the javascript function runs. To run server code that uses values from the client code, you have to send another request to the server and send the values along in the request. You can send values either in querystring or in form data. To populate a second select box depending on the first, you can either reload the page to do the request to the server, or do the request behind the scenes using techniques like AJAX.
--- single minded; short sighted; long gone;
hai thanks for the reply. Is it possible using hidden field?
-
hai thanks for the reply. Is it possible using hidden field?
-
ganeshMohan wrote:
Is it possible using hidden field?
Yes.
--- single minded; short sighted; long gone;
hai please give me a example code?