I have a form that when you select 'Yes' from a drop down menu a field appears. The projects requires that I make the field mandatory if the option of yes is selected fro the drop down.
I am using this as my Javascript validation...
And this to make the field appear...Code:<script language="JavaScript"> <!-- function formCheck(formobj){ // Enter name of mandatory fields var fieldRequired = Array("firstname", "lastname", "email", "homephone", "mailingaddress", "city", "province", "postalcode", "country", "Condo Type", "Price Range", "Agent"); // Enter field description to appear in the dialog box var fieldDescription = Array("First Name", "Last Name", "Email", "Phone", "Address", "City", "State or Province", "Zip or Postal", "Country", "Condo Type", "Price Range", "Agent"); // dialog message var alertMsg = "Please complete the following fields:\n"; 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 == 0 || 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 (formobj.Agent.selectedIndex == 1) { formobj.listid.value = "61785"; } else if (formobj.Agent.selectedIndex == 2) { formobj.listid.value = "61741,61744"; } if (alertMsg.length == l_Msg){ return true; }else{ alert(alertMsg); return false; } } // --> </script>
I am not a Java person by anymeans so I don't even know where to start, but is it simple enough to have some type of 'if' command in the validation that look for the fields visability?Code:<script type="text/javascript"> var LocnInfo = { 'Prospect':'', 'Broker':'Brokerage Name*: <input type="text" name="brokerage" id="brokerage" />' } function UpdateLocation(info) { document.getElementById('locnMsg').innerHTML = LocnInfo[info]; } </script>
Pointers are great but if you know of any tutorials or step by steps, that would be great. Telling me it's possible still leaves me stumped.



Reply With Quote


Bookmarks