0

I have a multi form,
In a form, i have the <back and Next> button.
So i used the form action in these to button, I also have a validation which i did using javascript ,

<head>
<script type="text/javascript">
function validate_name(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
  {alert(alerttxt);return false}
else {return true}
}
}

function validate_form(thisform)
{
with (thisform)
{
if (validate_name(txt_name,"Please enter the Name!")==false)
  {
  txt_name.focus();return false
  } 
}
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="" onsubmit="return validate_form(this);">
</form>
</body>

so , added the javascript function in form.. The validation works good..but after that it doesnt bring me to the next page..


This is the code that i added in next button,

<input type="submit" name="button" id="button" value="Next &gt;&gt;" onClick="form.action='creport3.php';" />

But if i want to add the validation also, where do i add it.. it needs to be added in the next button onclick event, but how will be the code...
Any help pls..

2
Contributors
3
Replies
13
Views
7 Years
Discussion Span
Last Post by diafol
0

Set the js function to your submit button as opposed to your form action. Then you need to check the client-side validation result. If all ok do a

document.form1.submit();
0

Set the js function to your submit button as opposed to your form action. Then you need to check the client-side validation result. If all ok do a

document.form1.submit();

'
Wr do i add the code ?

0

AT the end of your js validation code. Your validation routine will either pop an error or give the green light, e.g.

...check for validation errors...

if(errors == 0){
  document.form1.submit();
}else{
 ... do your error code handling here ...
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.