I'm trying to have 3 fields mandatory in my web form: First Name, Last Name and Phone number.
I inserted this code but it only works for Last name and if I leave the others empty, it accepts the entry:
<script>
// if you need to have some fields to be mandatory, please add them here within quotes ("") separate by comma (,).
var fieldIdarray=new Array("Last Name","First Name","Phone"); //This is used for the Validation.
var fieldNamearray=new Array("Last Name","First Name","Phone number"); //This is used for alert messages.
function validate()
{
for(var i=0;i<fieldIdarray.length;i++)
{
var value=document.getElementsByName(fieldIdarray[i])[0].value;
if(value=="" || value =="-None-" )
{
alert(fieldNamearray[i]+" cannot be empty");return false;
}
}
}
</script>
Then I noticed that there is another native validation at the end of the code which seems to work exactly the same but I don't know how to duplicate it to add the validation of the two others fields:
<script> var mndFileds=new Array('Last Name');var fldLangVal=new Array('Last Name');function checkMandatery(){for(i=0;i<mndFileds.length;i++){ var fieldObj=document.forms['WebToLeads650260000000256159'][mndFileds[i]];if(fieldObj) {if(((fieldObj.value).replace(/^\s+|\s+$/g, '')).length==0){alert(fldLangVal[i] +' can not be empty'); fieldObj.focus(); return false;}else if(fieldObj.nodeName=='SELECT'){if(fieldObj.options[fieldObj.selectedIndex].value=='-None-'){alert(fldLangVal[i] +' can not be « None »'); fieldObj.focus(); return false;}}}}}</script>
Any idea?
Thanks to the developers able to help me with the code because I'm definitly not a coder ;-)
Valérie
(I'm French so any help in French or in detailed English would help me!! LOL)