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.


In reply to Re: CGI JS confusion by Anonymous Monk
in thread CGI JS confusion by SerZKO

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.