...

View Full Version : Need help on sending javascript variable to ASP



LondonBoy
04-10-2007, 04:49 PM
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?


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>

Daemonspyre
04-10-2007, 07:21 PM
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.

degsy
04-18-2007, 03:32 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum