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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form submission and accessing perl variables

Status
Not open for further replies.

joeblow3

Programmer
Jun 9, 2008
21
CA
In a form, how do you get access to a perl variable (for example $error_message) in my javascript code encoded in the same html page?

Just saying "$error_message" doesn't work. The only way I currently know how is by creating a hidden field in my form and setting the value to be $error_message:

print "<input type=\"hidden\" name=\"error_message\" value=\"$error_message\" />\n";

and then passing it as a parameter to the javascript code:

print "<input type=\"button\" name = \"button\" value=\"Log in\"
onclick=\"somefunction(myForm.error_message.value)\" />\n";


My javascript code chooses betweeen two different places to go to depending on the value of $error_message like so:


print "<SCRIPT language=\"javascript\" >\n";
print " function somefunction(fd)\n";
print "{\n";
print "alert(fd)\n";
print "if (fd==''){\n";
print "document.invisible.submit()}\n";
print "else {document.myForm.submit()}\n";
print "}\n";
print "</SCRIPT>\n";


However, I have found out that the value of my error_message variable is one step behind i.e. if I am at step 2, it still has the value of step 1; and if I am at step 3 it still is at step 2 etc.

This results in me having to hit the submit button twice before the form is submitted.

I also tried: document.getElementById('error_message').value but it is still out of step by 1.

 
If $error_message is 1 step behind if you include it in your JS but not in your form, I'd be thinking that something is wrong somewhere.

Surely it should hold the correct value no matter where on your page you put it? Perhaps asking in the perl forum might be a better idea?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top