Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting a server-side hidden variable in client-side script

Status
Not open for further replies.

wrbodine

Programmer
Aug 24, 2000
302
US
Hi,

I'm trying to submit a form when I click on an image, and set a variable within that form to a specific value, depending on which image was clicked on. How can I set that variable in client-side script? (JavaScript or VBScript is fine). Here's some of the page's code below. With this code I get an error on the line where I try and set the value saying:

Error: 'document.MyForm.vari' is null or not an object


<head>

<script language=&quot;JavaScript&quot;)

function CheckValues(cond, value) {

...
if (cond == &quot;end&quot;) {
document.MyForm.vari.value = value;
document.MyForm.Submit();
}

// 3 other if conditions (not really necessary, but how I was doing it at first...)

}

</script>

<body>
<form ACTION=&quot;DailyJumboForm.asp&quot; METHOD=&quot;POST&quot; name=&quot;MyForm&quot;>

...
<input type=&quot;hidden&quot; name=&quot;vari&quot; value=&quot;<%=strVari%>&quot;>

<input type=&quot;image&quot; src=&quot;../../../images/btnForwardArrowLine.gif&quot; onClick=&quot;Javascript:Arrows('end', 'endValue');&quot;>

3 other images

...
</form>

Thanks,
Ray
 
hi,

use the following code. this coding will set the value 1 or 2 or 3 in the &quot;hidvalue&quot; field of &quot;frmtest&quot; form. this value will be changed depends upon the image u click. after the image clicked this form will be submitted to &quot;javascript1.asp&quot; where u can get the value of the hidden field by using request.form(&quot;hidvalue&quot;).

hope this code will be helpful to u in some way.

by
lenin
lenin_j@rediffmail.com


<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<TITLE></TITLE>
<SCRIPT LANGUAGE=javascript>
<!--
function setvalue(num)
{
document.frmtest.hidvalue.value = num
document.frmtest.submit()
}
//-->
</SCRIPT>

</HEAD>
<BODY>
<form name=&quot;frmtest&quot; method=&quot;post&quot; action=&quot;javascript1.asp&quot;>
<input type=hidden name=hidvalue>
<a href=&quot;javascript:setvalue(1)&quot;><img src=&quot;p1.jpg&quot;></a>
<BR>
<a href=&quot;javascript:setvalue(2)&quot;><img src=&quot;p2.jpg&quot;></a>
<BR>
<a href=&quot;javascript:setvalue(3)&quot;><img src=&quot;p3.jpg&quot;></a>
<BR>
</form>
</BODY>
</HTML>
 
Thanks Lenin,

for some reason I'm still getting the same error with this code. Maybe it's something I haven't noticed yet....
 
Have you tried change

&quot;onClick=&quot;Javascript:Arrows('end', 'endValue');&quot;

to

&quot;onClick=&quot;Javascript:CheckValues('end', 'endValue');&quot;?

Good luck,
 
Yeah, thanks, I actually ended up calling it setvalue in both places; I've tried passing a string or an int, and that didn't make a difference either...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top