Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to pass a javascript variable into asp variable?

how to pass a javascript variable into asp variable?

Scheduled Pinned Locked Moved ASP.NET
helpjavascriptdatabasetutorialquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    ganeshMohan
    wrote on last edited by
    #1

    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

    G 1 Reply Last reply
    0
    • G ganeshMohan

      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

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      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;

      G 1 Reply Last reply
      0
      • G Guffa

        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;

        G Offline
        G Offline
        ganeshMohan
        wrote on last edited by
        #3

        hai thanks for the reply. Is it possible using hidden field?

        G 1 Reply Last reply
        0
        • G ganeshMohan

          hai thanks for the reply. Is it possible using hidden field?

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          ganeshMohan wrote:

          Is it possible using hidden field?

          Yes.

          --- single minded; short sighted; long gone;

          G 1 Reply Last reply
          0
          • G Guffa

            ganeshMohan wrote:

            Is it possible using hidden field?

            Yes.

            --- single minded; short sighted; long gone;

            G Offline
            G Offline
            ganeshMohan
            wrote on last edited by
            #5

            hai please give me a example code?

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups