Home: Perl Programming Help: Beginner:
'OnClick' command



LeoMcCauley
New User

Oct 5, 2013, 7:26 AM


Views: 3004
'OnClick' command

Hi, sorry if I am wasteing your time but I am struggling with a simple onclick command inside a perl script.
I am simply trying to generate an onclick button but failing miserably! I'm sure I must be mising something basic.
Where is this "648245 648245" coming from?


The html output required is
<input value="Edit Record" type="button" onClick="$('#editform').submit();">

the print statement I am using in the cgi script is
print "<input value=\"Edit Record\" type=\"button\" onClick=\"$('#editform').submit();\">\n";

but the result in the browser is
<input value="Edit Record" type="button" onClick="648245 648245'#editform').submit();">


BillKSmith
Veteran

Oct 5, 2013, 7:57 AM


Views: 2999
Re: [LeoMcCauley] 'OnClick' command

You are using a double quoted string. That interpolates all variables including the special variable $GROUP_ID (refer: perldoc perlvar). Getting quotes and escapes right is tricky. It usually helps to use the 'quote like operators q() and qq() (refer perldoc perlop).

Even better, use the CGI module to generate your html.
Good Luck,
Bill


LeoMcCauley
New User

Oct 5, 2013, 8:22 AM


Views: 2997
Re: [BillKSmith] 'OnClick' command

Thanks for the reply Bill. Over my head, need to try and get to grips with it. Just can't get my head around the "648245 648245" and where it comes from. Thanks anyway


LeoMcCauley
New User

Oct 5, 2013, 9:13 AM


Views: 2991
Re: [BillKSmith] 'OnClick' command

Hi just to close this out, I found my problem

the print statement should be,



print "<input value=\"Edit Record\" type=\"button\" onClick=\"\$('#editform').submit();\">\n";

there was a \ missing before the $('

The print statement now produces the desired result.

ie

<input value="Edit Record" type="button" onClick="$('#editform').submit();">


BillKSmith
Veteran

Oct 5, 2013, 11:38 AM


Views: 2986
Re: [LeoMcCauley] 'OnClick' command

Your solution is correct, but rather awkward. I prefer:

Code
q(<input value="Edit Record" type="button" onClick="$('#editform').submit();>)."\n";

Please read my references.

Type:

Code
perldoc perldoc

at your command line to learn how to use the perldoc tool.

Without your new backslash, the characters '$(' were treated as the special variable $GROUP_ID. The value of that variable was interpolated (expanded) into your string and printed.
Good Luck,
Bill


LeoMcCauley
New User

Oct 5, 2013, 12:19 PM


Views: 2984
Re: [BillKSmith] 'OnClick' command

Thanks Bill