Even though you already found your answer, I wish to complain about your needless use of javascript.
(There are quite a many names I could call a web developer who relies too much on javascript, but my stance is, in a nutshell: everything that can be written without javascript, should be written without javascript, unless the effort needed to do that is extraordinary. And a lot of times, it is far from extraordinary. You can do a lot without JS.)
So you have a form. It looks like the image below.
# form that submits to kon.cgi
Do you want to change data for $clrNr?
[ Yes ] [ No ]
The "Yes" button goes to kon.cgi, and the "No" button has a javascript redirect to kon_add.html. This is not needed; nor will it work if the user has chosen to disable javascript. There are a few options to fix that.
What you could do is have two forms. One submits to kon.cgi, and the other to kon_add.html. Neither form will have data fields, but you are free to add data to one, if necessary.
# form that submits to kon.cgi
Do you want to change data for $clrNr?
[ Yes ]
# form that submits to kon_add.html
[ No ]
Of course, to the user it would look pretty much the same (well, after some fixing of the CSS at least) -- he doesn't see where which button submits to. So what about the code?
print $qry->start_form(-action => "http://skinnmaskin/cgi-bin/kon.cgi"
+);
print $qry->h4("Vill du \xE4ndra data f\xF6r $clrNr ?<br>");
print $qry->submit('Andra', 'Ja');
print $qry->end_form;
print $qry->start_form(-action => "http://skinnmaskin/mx/kon_add.html"
+);
print $qry->submit(-name =>'andra', -value=>'Nej');
print $qry->end_form;
No, kon_add.html need not be a CGI script. Your web server will serve it normally.
What do we gain here? Just getting rid of the javascript dependency -- now the user can use both of the buttons even on the text-mode Lynx browser (It's a very good browser -- you ought to try it.) And so can the conservative web users who prefer browsing without javascript. We seem to be in the minority.
There is another option -- having kon.cgi redirect to the correct place. We need to give the submit buttons different names. (Well, strictly speaking, we don't, but it will save some headache in an indeterminate point of time in the future.)
print $qry->submit('Andra', 'Ja'), $qry->submit(-name =>'addera', -val
+ue=>'Nej');
And the top of kon.cgi should be something like this:
if ($qry->param('addera')) {
# the "no" button was clicked
print $qry->redirect('http://skinnmaskin/mx/kon_add.html');
exit 0;
}
Anyway, I've only learned javascript through osmosis, and wish that you chose a non-JS solution to your problem, but I suspect your problem could be fixed by adding a "return false" to your JS. This will "disable" the second submit button if the JS is run.
I hope this helps. |