[cgiapp] Javascript to set multiple form params
Hi all. I ve been having problems when I had forms that would have multiple submit buttons (or links) such as user lists with multiple edit/delete buttons. Its fine if I wanted to use GETs but I real pain if I used POSTs. I have written a little Javascript function that takes the form name as it's first parameter and key, value pairs of the input field name and value I want to set it to. In order to use it, you create all your fields into hidden (or normal) fields in the form and then when you want to submit the form you have an onClick action for the button. I also provided a proof of concept script that takes the parameters and just prints them out on a page. There are many possibilities with C::A especially if you are obsessed with POSTs like me. You can have a single form for all of your template and change the runmode dynamically onClick (I have forms that will call Edit/Delete depending on the button you press) I hope it helps and people find it useful. I m also open to comments and suggestions on this and any other ways people use to do similar stuff. html head titleHash function/title script type=text/javascript language=javascript function hashprint() { // Take any number of parameters and return the sum var myHashtable = new Object(); var formName = arguments[0]; // alert(Formname: + formName); for (var i = 1; i arguments.length - 1; i = i + 2) myHashtable[arguments[i]] = arguments[i+1]; //for (var inpName in myHashtable) alert('document.' + formName + '.' + inpName + '.value = ' + myHashtable[inpName] + ''); for (var inpName in myHashtable) eval ('document.' + formName + '.' + inpName + '.value = ' + myHashtable[inpName] + ''); eval (document. + formName + .submit()); return false; } /script /head body Hi. Press the button form name=testform action=/cgi-bin/checkvars.pl method=POST input type=hidden name=action value= input type=hidden name=silent value= input type=hidden name=level value= input type=hidden name=help_topic value= input type=button value=Click Here onClick=hashprint('testform', 'action', 'actionfield1_value', 'silent', 'silentfield2_value', 'level', 'levelfield3_value', 'help_topic', 'help_topicfield4_value'); return falsebr /form /body /html -- #!/usr/bin/perl -w use strict; # System includes use CGI; # Echo back what we have my $CGI = CGI-new(); my %params = $CGI-Vars(); # Prep the server print Content-Type: text/html\n\n; my $username = $params{'username'}; my $action = $params{'action'}; my $silent = $params{'silent'}; my $root_level = $params{'level'}; my $help_topic = $params{'help_topic'}; # Header print Hellobr; print The variables are:br; print \$action = [$action]br; print \$silent = [$silent]br; print \$root_level = [$root_level]br; print \$help_topic = [$help_topic]br; print Thank youbr; exit(0); Dimitris Papaharisis - Web Archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ http://marc.theaimsgroup.com/?l=cgiappr=1w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: [cgiapp] Javascript to set multiple form params
Hi bret. I m not the strongest one iether and dont particularly like using it but it is the only way I could find to do what I wanted. I would be more than happy to implement that in my superclass but how? Could you please provide me with an example of some code? -Original Message- From: Brett Sanger [mailto:[EMAIL PROTECTED] Sent: 07 November 2003 14:50 To: Dimitris Papaharisis Cc: [EMAIL PROTECTED] Subject: Re: [cgiapp] Javascript to set multiple form params On Fri, Nov 07, 2003 at 09:34:22AM -, Dimitris Papaharisis wrote: Hi all. I ve been having problems when I had forms that would have multiple submit buttons (or links) such as user lists with multiple edit/delete buttons. Its fine if I wanted to use GETs but I real pain if I used POSTs. I have written a little Javascript function that takes the form name as it's first parameter and key, value pairs of the input field name and value I want to set it to. I'm not strong on my javascript, but that's because I tend to avoid it...it breaks in weird and unpredictable ways between browsers (even when something is labelled as compatible, the alignment of Venus seems to disturb it), it's a pain to maintain, bloats the pagesize, and doesn't work if they have it turned off or are using any of the new handhelds/smartphones/whatnots that don't support javascript. (And as an onClick, now your page doesn't work at all) So could you tell me if this is any different that embedding a similar function in your CGI::App subclass? -- SwiftOne / Brett Sanger [EMAIL PROTECTED] - Web Archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ http://marc.theaimsgroup.com/?l=cgiappr=1w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: [cgiapp] Javascript to set multiple form params
Yea ... Id like to know too. I'm now using a lot of very basic, compatible JavaScript, because it seems to be the only way to do some things without bloating the CGI world. Here a couple of examples of how I use JavaScript, that if somebody would like to provide an alternate solution, I would rather not use: 1. I too have pages with hidden's inside forms. Some of the forms are just dummy forms used for passing params to another run-mode. For example, I have many different pages that derive data from MySQL and display data in a grid-type fashion. On the page there may be a button to add a new record, and then two buttons for each record; one to delete the record and the other to delete the record. Each button calls a JavaScript function to set hidden params, prompt the user, submit the form, etc. The delete record button submits the current form with params back to the current run-mode and with a ctrl param set to 'del' and I delete the record. The Add and Edit buttons submit to a different form (also changing the run-mode) with ctrl params = 'add' and 'edit', respectively and I present a data entry or edit form (each having a differnet run-mode.) Then these forms submit back to the previous run-mode for SQL processing. It all works and works pretty well, but if there's a BETTER way (there's always ANOTHER way,) I'd sure like to know: I've got a lot of development time wrapped up into the way I'm doing things now and I played around with more than a few others before deciding on my current methodology. 2. The other thing I'm using JavaScript for that I can't see doing another way (without embedding Perl,) is to create dynamic select boxes. Ala Delphi, I use JavaScript to create a hashed datasources in the window object and attach the select boxes to a datasource. Then I can link or chain together multiple select boxes to create record filters and other such things that don't need the page to reload in order to refine the option's. So again, if there's a better way, I'd sure like to know. BTW, as an OT aside, I think we're getting close to a world where JavaScript/Browser incompatibilities will be a thing of the past. Also, I remember during the rapid growth days of the WWW, many web sites disclaimed that you need a specific browser in order to use the site or some such nonsense. I think for some applications (maybe very few), it's not such a terrible thing that a client needs a specific browser or version thereof, thereby forgoing all the idiotic browser/version checking madness. So, JavaScript does seem to have a place and it certainly doesn't appear to be going away ... at least until browsers provide Perl interpreters to handle user events :) -Original Message- From: Dimitris Papaharisis [mailto:[EMAIL PROTECTED] Sent: Friday, November 07, 2003 8:56 AM To: Brett Sanger Cc: [EMAIL PROTECTED] Subject: RE: [cgiapp] Javascript to set multiple form params Hi bret. I m not the strongest one iether and dont particularly like using it but it is the only way I could find to do what I wanted. I would be more than happy to implement that in my superclass but how? Could you please provide me with an example of some code? -Original Message- From: Brett Sanger [mailto:[EMAIL PROTECTED] Sent: 07 November 2003 14:50 To: Dimitris Papaharisis Cc: [EMAIL PROTECTED] Subject: Re: [cgiapp] Javascript to set multiple form params On Fri, Nov 07, 2003 at 09:34:22AM -, Dimitris Papaharisis wrote: Hi all. I ve been having problems when I had forms that would have multiple submit buttons (or links) such as user lists with multiple edit/delete buttons. Its fine if I wanted to use GETs but I real pain if I used POSTs. I have written a little Javascript function that takes the form name as it's first parameter and key, value pairs of the input field name and value I want to set it to. I'm not strong on my javascript, but that's because I tend to avoid it...it breaks in weird and unpredictable ways between browsers (even when something is labelled as compatible, the alignment of Venus seems to disturb it), it's a pain to maintain, bloats the pagesize, and doesn't work if they have it turned off or are using any of the new handhelds/smartphones/whatnots that don't support javascript. (And as an onClick, now your page doesn't work at all) So could you tell me if this is any different that embedding a similar function in your CGI::App subclass? -- SwiftOne / Brett Sanger [EMAIL PROTECTED] - Web Archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ http://marc.theaimsgroup.com/?l=cgiappr=1w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - Web Archive: http://www.mail-archive.com/[EMAIL PROTECTED]/
Re: [cgiapp] Javascript to set multiple form params
1. I too have pages with hidden's inside forms. Some of the forms are just dummy forms used for passing params to another run-mode. For example, I have This can be done with a run mode that calls other run modes based on some data (whatever data the Javascript uses, unless you're using image-based submit buttons). Mostly though I admit to using GET links when I want to call such things. In such a case, I usually only need to pass some sort of ID, so it's not an ugly link regardless. run-mode for SQL processing. It all works and works pretty well, but if there's a BETTER way (there's always ANOTHER way,) I'd sure like to know: Better depends on what you value. I avoid javascript like the plague because: 1) I work at a govt site, so maximum compatibility is important 2) I've found the value/effort ratio to be poor 3) I'm personally not fond of it :) You may have equally valid reasons for wanting more javascript and less perl work. I wasn't actually trying to criticise the original poster, I was just trying to understand what he was doing to see if it _required_ Javascript. 2. The other thing I'm using JavaScript for that I can't see doing another way (without embedding Perl,) is to create dynamic select boxes. Ala Nope, no way of doing that short of some sort of client-side interpretation. I can completely appreciate why you'd want this too. BTW, as an OT aside, I think we're getting close to a world where JavaScript/Browser incompatibilities will be a thing of the past. Also, I Since I just got a HipTop, which doesn't support javascript, and my bank just updated their online banking page to use some buggy JS that Moz 1.5 doesn't run. (silently fails to do anything) I can't say I agree, as far as the short term goes. remember during the rapid growth days of the WWW, many web sites disclaimed that you need a specific browser in order to use the site or some such They've stopped SAYING it, but it's still every bit as true. It's just that 95% of the world is running a kind of recent version of IE. nonsense. I think for some applications (maybe very few), it's not such a terrible thing that a client needs a specific browser or version thereof, Agreed. The correct tool for the correct job, etc. JavaScript does seem to have a place and it certainly doesn't appear to be going away ... at least until browsers provide Perl interpreters to handle user events :) Also agreed. That doesn't mean I will encourage people to use it outside of its place, but that's flame war material outside the scope of this list. :) -- SwiftOne / Brett Sanger [EMAIL PROTECTED] - Web Archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ http://marc.theaimsgroup.com/?l=cgiappr=1w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [cgiapp] Javascript to set multiple form params
On Fri, 7 Nov 2003 16:53:41 -0500, Brett Sanger wrote: Hi Folks 2. The other thing I'm using JavaScript for that I can't see doing another way (without embedding Perl,) is to create dynamic select boxes. Ala Nope, no way of doing that short of some sort of client-side interpretation. I can completely appreciate why you'd want this too. DBIx::HTML::LinkedMenus may help. See: http://savage.net.au/Perl-modules/html/DBIx/HTML/LinkedMenus.html -- Ron Savage, [EMAIL PROTECTED] on 8/11/2003. Room EF 312 Deakin University, 221 Burwood Highway, Burwood, VIC 3125, Australia Phone: +61-3-9251 7067, Fax: +61-3-9251 7604 http://www.deakin.edu.au/~rons - Web Archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ http://marc.theaimsgroup.com/?l=cgiappr=1w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: [cgiapp] Javascript to set multiple form params
That's great but I just finished rolling my own. Looks pretty much like the same thing I've got here. I wish I would have found that about 2 weeks ago. I didn't think to check CPAN because JavaScript was involved. Well ... live and learn; and I have learned a lot!!! Now I have a very solid understanding of JS to add to my bag of tricks and that's not such a bad thing. Bill -Original Message- From: Ron Savage [mailto:[EMAIL PROTECTED] Sent: Friday, November 07, 2003 6:55 PM To: Perl: CGI::Application Subject: Re: [cgiapp] Javascript to set multiple form params On Fri, 7 Nov 2003 16:53:41 -0500, Brett Sanger wrote: Hi Folks 2. The other thing I'm using JavaScript for that I can't see doing another way (without embedding Perl,) is to create dynamic select boxes. Ala Nope, no way of doing that short of some sort of client-side interpretation. I can completely appreciate why you'd want this too. DBIx::HTML::LinkedMenus may help. See: http://savage.net.au/Perl-modules/html/DBIx/HTML/LinkedMenus.html -- Ron Savage, [EMAIL PROTECTED] on 8/11/2003. Room EF 312 Deakin University, 221 Burwood Highway, Burwood, VIC 3125, Australia Phone: +61-3-9251 7067, Fax: +61-3-9251 7604 http://www.deakin.edu.au/~rons - Web Archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ http://marc.theaimsgroup.com/?l=cgiappr=1w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - Web Archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ http://marc.theaimsgroup.com/?l=cgiappr=1w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]