html - Javascript validation for my report page -
i have table generate reports. need write javascript validation 1 report. unfortunately, javascript weak. have server side validation in place, need have javascript validation. page follows...
<tr> <form name="medicaidresidents" action="medicaid_residents.cfm" method="post" id='f1' onsubmit="validateform(this.form);"> <td nowrap="nowrap"> medicaid residents </td> <td style="width: 5%;"> <table style="width: 5%;"> <tr> <td style="width: 5%;"><br><br> <input type="radio" name="choice" value='1' onclick="check_radio()";>all<br><br> <input type="radio" name="choice" value='2' onclick="check_radio()";>states<br><br> <input type="radio" name="choice" value='3' onclick="check_radio()";>communities </td> <td style="width: 5%;"> <select name="stateprompt1" multiple="multiple" size="10" id="t1"> <cfloop query="medicaid_states"> <option value="#medicaid_states.state_code#">#medicaid_states.state_code#</option> </cfloop> </select> </td> <td style="width: 10%;"> <select name="houseprompt1" multiple="multiple" size="10" id="t2"> <cfloop query="medicaid_houses"> <option value="#medicaid_houses.ihouse_id#">#medicaid_houses.community# </option> </cfloop> </select> </td> </tr> </table> </td> <td> <table style="width: 5%;"> <tr> <td> </td> </tr> <tr> <td> <input type="text" id="txtfromdate" name="dateprompt1"> </td> </tr> <tr> <td> </td> </tr> <tr> <td> </td> </tr> <tr> <td> <input type="text" id="txttodate" name="dateprompt2"> </td> </tr> </table> </td> <td> <input type="submit" name="go" value="go" style="font-size: 12; color: navy; height: 20px; width: 60px;"> </td> </form> </tr> the javascript wrote is...
<script language="javascript"> function validateform(form){ if ( ( form.choice[0].checked == false ) && ( form.choice[1].checked == false ) && ( form.choice[2].checked == false ) ) { alert ( "please first select radiobutton" ); return false; } elseif ( ( form.choice[1].checked == true ) && ( document.getelementbyid("t1").value=="")) { alert ( "please select state" ); return false; } elseif ( ( form.choice[2].checked == true ) && ( document.getelementbyid("t2").value=="")) { alert ( "please select house" ); return false; } elseif ( ( document.dateprompt1.value =="") && ( document.dateprompt2.value=="")) { alert ( "please select 'from' , 'to' dates" ); return false; } } </script> ...but doesn't work. know javascript poorly writen. appreciate in getting work!
rather have series of else statements have if statements because stop return false, , green/passed path/action @ bottom.
function validateform(){ var = document.forms["medicaidresidents"]["choice"].value; var b = document.forms["medicaidresidents"]["stateprompt1"].value; var c = document.forms["medicaidresidents"]["houseprompt1"].value; var d = document.forms["medicaidresidents"]["dateprompt1"].value; var e = document.forms["medicaidresidents"]["dateprompt2"].value; if (a == null || == "") { alert("please first select radiobutton"); return false; } if (b == null || b == "") { alert("please select state"); return false; } if (c == null || c == "") { alert("please select house"); return false; } if (d == null || d == "" && e == null || e == "") { alert("please select 'from' , 'to' dates"); return false; } return true; } <tr> <form name="medicaidresidents" action="medicaid_residents.cfm" method="post" id='f1' onsubmit="return validateform();"> <td nowrap="nowrap"> medicaid residents </td> <td style="width: 5%;"> <table style="width: 5%;"> <tr> <td style="width: 5%;"><br><br> <input type="radio" name="choice" value='1' onclick="check_radio()">all<br><br> <input type="radio" name="choice" value='2' onclick="check_radio()">states<br><br> <input type="radio" name="choice" value='3' onclick="check_radio()">communities </td> <td style="width: 5%;"> <select name="stateprompt1" multiple="multiple" size="10" id="t1"> <cfloop query="medicaid_states"> <option value="#medicaid_states.state_code#">#medicaid_states.state_code#</option> </cfloop> </select> </td> <td style="width: 10%;"> <select name="houseprompt1" multiple="multiple" size="10" id="t2"> <cfloop query="medicaid_houses"> <option value="#medicaid_houses.ihouse_id#">#medicaid_houses.community# </option> </cfloop> </select> </td> </tr> </table> </td> <td> <table style="width: 5%;"> <tr> <td> </td> </tr> <tr> <td> <input type="text" id="txtfromdate" name="dateprompt1"> </td> </tr> <tr> <td> </td> </tr> <tr> <td> </td> </tr> <tr> <td> <input type="text" id="txttodate" name="dateprompt2"> </td> </tr> </table> </td> <td> <input type="submit" name="go" value="go" style="font-size: 12; color: navy; height: 20px; width: 60px;"> </td> </form> </tr>
Comments
Post a Comment