CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



LeoMcCauley
New User

Oct 5, 2013, 7:26 AM

Post #1 of 6 (981 views)
'OnClick' command Can't Post

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

Post #2 of 6 (976 views)
Re: [LeoMcCauley] 'OnClick' command [In reply to] Can't Post

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

Post #3 of 6 (974 views)
Re: [BillKSmith] 'OnClick' command [In reply to] Can't Post

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

Post #4 of 6 (968 views)
Re: [BillKSmith] 'OnClick' command [In reply to] Can't Post

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

Post #5 of 6 (963 views)
Re: [LeoMcCauley] 'OnClick' command [In reply to] Can't Post

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

Post #6 of 6 (961 views)
Re: [BillKSmith] 'OnClick' command [In reply to] Can't Post

Thanks Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives