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..

Recommended Answers

All 3 Replies

Member Avatar for diafol

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();

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 ?

Member Avatar for diafol

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 ...
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.