Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help on sending javascript variable to ASP

    ok this code, I got a href link that works with a counter for the value in a javascript variable, i put that value in a hidden field, then assign that value to a javascript variable.

    But it's not working, can anyone help me?

    Code:
    Loccustom=request.form("custom")
     
     <input type="hidden" name="custom" value=""  />
     </form>
     
    var global=0;
    function dynamic()
    {
    var tmp=1;
    global=global+tmp;
    alert(tmp)
    alert(global)
    document.frm.custom.value=global;
    }
     
     
     
      <% if len(Loccustom)=0 then 
          else%>
          <tr>
            <td height="15" colspan="3" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> 
              <!--DWLayoutTable-->
             
           <tr>
            <td width="244" height="15" align="center" valign="middle"><!--DWLayoutEmptyCell-->&nbsp;</td> 
            <td width="168" align="center" valign="middle"><!--DWLayoutEmptyCell-->&nbsp;</td>
            <td width="163" align="center" valign="middle"><!--DWLayoutEmptyCell-->&nbsp;</td> 
              </tr>
              </table>
            </td>
              </tr> <%end if%>
          <tr>
                          <td height="15" colspan="3" valign="middle">&nbsp;&nbsp;<a href="javascript:dynamic();">Click here to add charges not in selection</a></td> 
               </tr>

  • #2
    Regular Coder
    Join Date
    Mar 2007
    Posts
    505
    Thanks
    1
    Thanked 19 Times in 19 Posts
    You aren't getting the value because you haven't submitted the form yet (at least not in the snippet you provided).

    And because ASP is server-side and JS is client-side, something has to happen to reload the page first.

    Have you tried modifying your dynamic() function to include a document.frm.submit()? That would force the Request.Form() to take on the value that JS has submitted.

  • #3
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you want javascript to communicate with ASP dynamically then you can use Ajax to call the ASP script, passing the variable in a querystring.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •