Menu
Hi there
I’m not a programmer but am faced with the task of trying to write a script which will check certain fields of a form, depending on which value has been selected from a drop down box. I have found many scripts that will check each field of a form but am unsure how to alter it to meet the needs of the form I’m working on.
Can anyone help?
Cheers ?
var l_Msg = alertMsg.length;
for (var i = 0; i < fieldRequired.length; i++){
var obj = formobj.elements[fieldRequired[i]];
if (obj){
switch(obj.type){
case "select-one":
if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
alertMsg += " - " + fieldDescription[i] + "n";
}
break;
case "select-multiple":
if (obj.selectedIndex == -1){
alertMsg += " - " + fieldDescription[i] + "n";
}
break;
case "text":
case "textarea":
if (obj.value == "" || obj.value == null){
alertMsg += " - " + fieldDescription[i] + "n";
}
break;
default:
}
if (obj.type == undefined){
var blnchecked = false;
for (var j = 0; j < obj.length; j++){
if (obj[j].checked){
blnchecked = true;
}
}
if (!blnchecked){
alertMsg += " - " + fieldDescription[i] + "n";
}
}
}
}
if (alertMsg.length == l_Msg){
//alert("Just between the two of us, form submitted!")
return true;
}else{
alert(alertMsg);
return false;
}
<TR>
<TD width="189"><P align="top"> Email Address / Fax Number or Postal Address :</P>
<P align="top"> </P>
</TD>
<TD colSpan=8><textarea name="D_ContactAddress" cols="50"></textarea></TD>
</TR>
</TBODY>
<tr>
<td>S/O Number:</td>
<td><input name="Y_ServiceOrderNumber" type="text" value="" size="50"></td>
</tr>
<tr>
<td width="189">Stage S/O is in: </td>
<td width="411"><input name="Z_ServiceOrderNumber" type="text" value="" size="50"></td>
</tr>
</tbody>
What original code do you mean?[/QUOTE]
<i>
</i>function formCheck(formobj){
<i> </i>var selectObject = document.getElementById('firstChoice');
<i> </i>if (selectObject.selectedIndex <= 0) {
<i> </i> alert('Select the reason for your request');
<i> </i> return false;
<i> </i>}
<i> </i>var alertMsg = '';
<i> </i>switch (selectObject.selectedIndex) {
<i> </i> case 1:
<i> </i> if (formobj.elements['C_EsnNumber'].value.length == 0) {
<i> </i> alertMsg += '[in proof: C_EsnNumber]n';
<i> </i> }
<i> </i> if (formobj.elements['D_ContactAddress'].value.length == 0) {
<i> </i> alertMsg += '[in proof: D_ContactAddress]n';
<i> </i> }
<i> </i> break;
<i> </i> case 2:
<i> </i> if (formobj.elements['G_StageOrderIn'].selectedIndex <= 0) {
<i> </i> alertMsg += '[in cancellation of order: G_StageOrderIn]n';
<i> </i> }
<i> </i> // need to check the other fields
<i> </i> // same goes for other cases
<i> </i> break;
<i> </i> case 3:
<i> </i> alertMsg = 'in courierpost';
<i> </i> break;
<i> </i> case 4:
<i> </i> alertMsg = 'in missing parts';
<i> </i> break;
<i> </i> case 5:
<i> </i> alertMsg = 'in missing promotional goods';
<i> </i> break;
<i> </i> case 6:
<i> </i> alertMsg = 'in change of address';
<i> </i> break;
<i> </i> case 7:
<i> </i> alertMsg = 'in dispatch confirmation';
<i> </i> break;
<i> </i>}
<i> </i>if (alertMsg.length > 0) {
<i> </i> alert(alertMsg);
<i> </i> return false;
<i> </i>}
}
0.1.9 — BETA 5.16