Debt Consolidation - Debt Consolidation - Article directory - Credit Reports - Song Lyrics

PDA

View Full Version : How to validate an ajax form with javascript?


123GoToAndPlay
Aug 16th 2007, 12:26 pm
hi,

My particular form start with 1 main pulldown, depending on the choice either formfieldsA.php or forrmfieldsB.php will be called by an ajax request.

But now i don't know how to set up the JS validation, like i have something in the line of:

<form name="Form" action="?action=step3" method="POST" onsubmit="return Validator(this);">
<select name="segment" id="segment" onchange="javascript:segmentForm2();">
<option value="">Segment</option>
<option value="formfieldsA.php">A</option>
<option value="formfieldsB.php">B</option>
</select>
<div id="formfields" style="display:none;">

</form>


Based on segment the fields from formfieldsA.php or forrmfieldsB.php will be called by an ajax request.

now for the validation part in index.php


function Validator(theForm){
if ( document.Form.segment.value==0)
{ alert('segment'); document.Form.segment.focus(); return false;}

if ( document.Form.cName.value.length<1)
{ alert('name'); document.Form.cName.focus(); return false;}

.....
}

works for all the fields in formfieldsA.php. But how do i check the fields in formfieldsB.php

Any ideas??

bibel
Aug 17th 2007, 12:00 am
You have to check first what formfield is selected
Now you only check if no formfield is selected :

if ( document.Form.segment.value==0)

You need to add :

if ( document.Form.segment.value=='formfieldsA.php'), and formfieldsB.php

and validate the fields according to the selected form

123GoToAndPlay
Aug 17th 2007, 3:08 am
@bibel, seems to work like a charm.

You help me out a lot, today. Tx!