[Javascript] Test or Identify Value of Submit Button's Assigned Value

Flavio Gomes flavio at economisa.com.br
Fri Jan 21 12:02:50 CST 2005


Hello Ron,


Maybe changing  your checkForm to something like

          function checkForm(pressedSubmit)   { ... }

then call it as

          <input type=submit onclick="checkForm(this.value)" name=action 
value=Inquire>
          <input type=submit onclick="checkForm(this.value)" name=action 
value=Update>

Or you could set a variable initiated with the default "value" of the 
submit, and when the user clicks the button (the submit) it changes the 
variable value to it's(button's) value.

--
Flavio Gomes
flavio at economisa.com.br



Ron Wingfield wrote:

> I have defined some submit buttons, e.g., assoc/w "Inquire", "Update", 
> etc.,  as follows:
>  
>
>     $cgi-> submit(-name=>"action", -value=>"Inquire"),
>     $cgi-> submit(-name=>"action", -value=>"Update"),
>
> Regarding the first "if" condition in the following JavaScript code 
> (from the checkForm function executed -onsubmit), the value of  " 
> form["action"].value " is /undefined/ (. . .at least at the point in 
> my code); however, the value of " form[''name"].value " is the value 
> as typed in the form's /Name/ field. 
>
>                  if ( form["action"].value == "Update") {
>                       if ( form["name"].value == "") {
>                           alert("Name is required");
>                       return false;
>                       }
>                  }
>
> Obviously, the following -onsubmit condition is executing the 
> JavaScript.  In the client-side JavaScript, how do I test the value of 
> the clicked submit button?  In other words, I need to know which 
> submit button was clicked.
>
>
>     $cgi->start_form(-action=>'vendors_01.pl',
>                   -method=>'GET',
>                   -name=>'vendors_01.pl',
>                   -onsubmit=>"return checkForm( this );" );
>
> Thanks,
> Ron Wingfield
>  
> FreeBSD 4.8  --  Apache http 2.0.28 -- MySQL client/server 4.1.7
> Perl 5.8.5 -- p5-DBD-mysql-2.9004 driver -- p5-DBI-1.46





More information about the Javascript mailing list