in reply to Re^4: [Re]confirm box
in thread [Re]confirm box
Okay sure, I just said that because it's strange to see all those print() and \n to output strings with embeddeded code. It just doesn't look nice visually (and probably not fun to debug if javascript gets big or halfway complicated).
Yup, using double quoted strings for everything is just a sign of being very new :) ... and skipping perlintro/perlquote
Another example of cgi101 , stuffing stuff inside subs is the idea, see sub RootPage, sub RootTemplate , ... and unclunky cgi and esp Re^5: I need help with displaying newline or paragraph using perl on my website (pass arguments more subs)
so the OP might write
sub checkform_js { return q{ function CheckForm_onclick() { var myForm = document.form1; var message = ""; message = "Confirm if you need to disable . Choose OK to go ah +ead and Cancel to abort."; var answer = confirm(message); if (answer == false ){ document.write('You chose to Cancel. Closed window.'); } else { document.getElementById("userresponse").value = "Yes"; document.form.submit(); } } }; } ## end sub checkform_js sub main_page { my( $title ) = @_; return '<html> <head> <LANGUAGE=Javascript> <script>', checkform_js(), '</SCRIPT> <title>', $title, '</title> </head> <body onload="return (CheckForm_onclick())"> <FORM action="disable.cgi" method="post"> <input type="hidden" name="userresponse" > </form> </body> </html> '; } ## end sub main_page
Thats not best way to write js either, but one thing at a time :)
One thing I don't understand in the example you linked though... Why did he use this double negation construction in the ValidLogin() sub: It seems redundant? Actually why even use any ! operators at all and just return the literal code you intend.
Well, its not a code, its a boolean, it forces boolean context, returns the true false "constants", see Re: Anybody use !!, Context tutorial
so its not good to pretend like its a code when its boolean -- in practice it doesn't really matter to perl, but in reading code it makes intent clear, its self documenting
|
|---|