I've a function that validate a form field:
<html>
<head>
<script language="JavaS cript">
function CheckFields(For mSubmit,BtnName )
{
if (BtnName!="Canc el")
{
check = true;
if (FormSubmit.Use r_Account.value == ""){
alert ("Username compulsory");
FormSubmit.User _Account.focus( );
return false;
}....
My FORM:
<form action="<?php echo $editFormAction ; ?>" name="formSubmi t"
method="POST"> <!--form action myself-->
....
<input type="submit" name="SubmitBut ton" value="Add"
onClick="CheckF ields(this.form , this.value)">
<input type="submit" name="SubmitBut ton" value="Cancel">
Now, if I click on cancel, I do redirect (with PHP) to a previous page. If I
click on Add, a check is done on the compulsory fields. I would like the
focus on the selected field (the one that isn't right), but the form is
reloaded. How to avoid this ?
I've tried to put the check on the form.OnSubmit (that fires before I submit
the form, and set the buttons input type as "button" instead of "submit"),
instead of the button click (that does submit the form), but I can't
retrieve with button was pushed. (I've tried FormSubmit.Subm itButton.name,
but it doesn't work)
Please help.
<html>
<head>
<script language="JavaS cript">
function CheckFields(For mSubmit,BtnName )
{
if (BtnName!="Canc el")
{
check = true;
if (FormSubmit.Use r_Account.value == ""){
alert ("Username compulsory");
FormSubmit.User _Account.focus( );
return false;
}....
My FORM:
<form action="<?php echo $editFormAction ; ?>" name="formSubmi t"
method="POST"> <!--form action myself-->
....
<input type="submit" name="SubmitBut ton" value="Add"
onClick="CheckF ields(this.form , this.value)">
<input type="submit" name="SubmitBut ton" value="Cancel">
Now, if I click on cancel, I do redirect (with PHP) to a previous page. If I
click on Add, a check is done on the compulsory fields. I would like the
focus on the selected field (the one that isn't right), but the form is
reloaded. How to avoid this ?
I've tried to put the check on the form.OnSubmit (that fires before I submit
the form, and set the buttons input type as "button" instead of "submit"),
instead of the button click (that does submit the form), but I can't
retrieve with button was pushed. (I've tried FormSubmit.Subm itButton.name,
but it doesn't work)
Please help.
Comment