Passing variable to ASP with javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave A

    #1

    Passing variable to ASP with javascript

    I have two events in a form that I am passing. One is to a javascript
    function, the other is to the same .asp page only with another action
    to show different data.

    Onchange is calls the function updateclasses, which in turn reloads
    another drop-down list. It also reloads the .asp page, which
    refreshes the data. My problem is that it refreshes the second
    drop-down briefly, until the page reloads, but then resets the form.
    How do i pass this data to the .asp?

    I thought in the .asp, I could just do something simple like the
    following, but wasn't sure of the correct syntax. is there a better
    way?

    view = request.queryst ring("view")
    if view = "" then
    view = "SciLink"
    else
    %>
    <script language="JavaS cript">
    updateclasses(f orm1, 0, Student)
    </script>
    <%
    end if



    <form name=form1 method=post>
    <td><span class=middleCol ContentBold>SOR T BY:</span><br>
    <select multiple class="rubricCo ntent"
    onchange="gotos ite(this.option s
    [this.selectedIn dex].value);updatec lasses(this.for m, 0,
    this.selectedIn dex)" style="backgrou nd-color:FFFFFF; border:1 solid
    black; width:110;">
    <option value="gradeboo k3.asp?view=Sci Link" <% if view = "SciLink"
    then response.write "selected" end if %>>SCILINKS</option>
    <option value="gradeboo k3.asp?view=Stu dent" <% if view = "Student"
    then response.write "selected" end if %>>CLASSES</option>
    </select>
    </td>
    </form>
  • DB McGee

    #2
    Re: Passing variable to ASP with javascript

    Dave A wrote:[color=blue]
    > I have two events in a form that I am passing. One is to a javascript
    > function, the other is to the same .asp page only with another action
    > to show different data.
    >
    > Onchange is calls the function updateclasses, which in turn reloads
    > another drop-down list. It also reloads the .asp page, which
    > refreshes the data. My problem is that it refreshes the second
    > drop-down briefly, until the page reloads, but then resets the form.
    > How do i pass this data to the .asp?[/color]

    Why not have the Javascript write the data to a hidden form field(s) then grab
    the POST'ed value in the ASP code?


    Comment

    • Dave Anderson

      #3
      Re: Passing variable to ASP with javascript

      Well, that makes sense. I'm new to javascript. How do you write to a
      hidden field?

      Where do I put it so the onchange still occurs?

      Thanks again

      Dave


      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • Evertjan.

        #4
        Re: Passing variable to ASP with javascript

        Dave A wrote on 20 jan 2004 in comp.lang.javas cript:[color=blue]
        > I have two events in a form that I am passing. One is to a javascript
        > function, the other is to the same .asp page only with another action
        > to show different data.[/color]

        ASP can be written in javascript, so that would be implicit.
        ASP does not equal vbscript, that can be clientside too [in IE]

        Do you want to send a clientside value to serverside?

        ============= test.asp ===============

        The value sent to serverside was:
        <% = request.form("x ") %>

        <form method=post id="y">
        <input type=hidden id="x" name="x">
        </form>

        <script>
        function z(val){
        document.getEle mentById("x").v alue = val;
        document.getEle mentById("y").s ubmit();
        }
        </script>

        <button onclick="z('3.1 4')">3.14</button>
        <button onclick="z('Hi' )">Hi</button>
        <button onclick="z('Bye ')">Bye</button>


        =============== =============== ===========

        --
        Evertjan.
        The Netherlands.
        (Please change the x'es to dots in my emailaddress)

        Comment

        • Dave Anderson

          #5
          Re: Passing variable to ASP with javascript


          On submitting the form, I am currently doing two things.

          Attempting to update a second selection box with the following function
          updateclasses(t his.form, 0,this.selected Index)"
          I am also send the form to the .asp page with
          onchange="gotos ite(this.option s this.selectedIn dex].value);

          <form name=form1 method=post>

          Currently, I am doing both of these in the onchange event. If I pass it
          to a hidden field, a request it on the page load, what do I put in the
          hidden field?

          <input type="hidden" name="test" value="updatecl asses(this.form ,
          0,this.selected Index)"">

          Thanks

          *** Sent via Developersdex http://www.developersdex.com ***
          Don't just participate in USENET...get rewarded for it!

          Comment

          • Evertjan.

            #6
            Re: Passing variable to ASP with javascript

            Dave Anderson wrote on 20 jan 2004 in comp.lang.javas cript:
            [color=blue]
            > <input type="hidden" name="test" value="updatecl asses(this.form ,
            > 0,this.selected Index)"">
            >[/color]

            You cannot code-"run" an html value

            Please explain what you are doing serverside and what clientside, primarily
            to yourself and also to us. I suspect you are mixing both.

            --
            Evertjan.
            The Netherlands.
            (Please change the x'es to dots in my emailaddress)

            Comment

            • Brian Genisio

              #7
              Re: Passing variable to ASP with javascript

              Dave Anderson wrote:[color=blue]
              > Well, that makes sense. I'm new to javascript. How do you write to a
              > hidden field?
              >
              > Where do I put it so the onchange still occurs?
              >
              > Thanks again
              >
              > Dave
              >
              >
              > *** Sent via Developersdex http://www.developersdex.com ***
              > Don't just participate in USENET...get rewarded for it![/color]

              Put this inside a form, and replace the name and value values:
              <input type=hidden name=some_name value=some_valu e>

              Brian


              Comment

              • Dave Anderson

                #8
                Re: Passing variable to ASP with javascript

                '<input type=hidden name=some_name value=some_valu e>
                '

                This I completely understand. What I don't understand, due to my lack of
                knowledge with javascript is what are those values? Currently, I am
                calling this function with an onchange event. How do I know what the
                function is passing?

                updateclasses(t his.form, 0, this.selectedIn dex)

                I assume this.form would be my form name form1
                What is this.selectedIn dex? The values of my options or their names?

                Also, once I request the variable, I assume I can just recall the
                function after the page loads?

                I apreciate everyone's patience and help with this. I may just be
                confusing the issue!

                Dave




                *** Sent via Developersdex http://www.developersdex.com ***
                Don't just participate in USENET...get rewarded for it!

                Comment

                Working...