bsamson Posted December 27, 2007 Share Posted December 27, 2007 Hello, I am very much new to Javascript. I have a form which is double checked for accuracy before submitting. This is my code (in the head): <script language="javascript" type="text/javascript"> <!-- // Hide the following code from non-Javascript enabled browsers function focus() // Define function focus { document.breakdown.sprintnew.focus(); } function checkme() // Define function checkme { if (document.breakdown.depositmade.value == "y") { if (document.breakdown.depositMOfrom.value == "mth" || document.breakdown.depositDYfrom.value == "day" || document.breakdown.depositMOto.value == "mth" || document.breakdown.depositDYto.value == "day") { alert("Please check your Deposit Date Range!"); document.breakdown.depositMOfrom.focus();return(false) } if (document.breakdown.deposit.value == "") { alert("Please check your Deposit Amount!"); document.breakdown.deposit.focus();return(false) } } } </SCRIPT> Now, the problem is ... well ... it doesn't work! I have double checks all of my field names and values to be sure it correspondes. All those match up so perhaps there must be a problem in code. As it stands it allows the form to be submitted w/ the incorrect values. any suggestions? Link to comment https://forums.phpfreaks.com/topic/83392-javascript-conditional-statements-embedded/ Share on other sites More sharing options...
phpQuestioner Posted December 28, 2007 Share Posted December 28, 2007 try this: <script language="javascript" type="text/javascript"> <!-- // Hide the following code from non-Javascript enabled browsers function focus() // Define function focus { document.breakdown.sprintnew.focus(); } function checkme() // Define function checkme { if (document.breakdown.depositmade.value == "y") { if (document.breakdown.depositMOfrom.value == "mth") { alert("Please check your Deposit Date Range!"); document.breakdown.depositMOfrom.focus();return(false) } if (document.breakdown.depositMOfrom.value == "day") { alert("Please check your Deposit Date Range!"); document.breakdown.depositMOfrom.focus();return(false) } if (document.breakdown.depositMOfrom.value == "") { alert("Please check your Deposit Amount!"); document.breakdown.depositMOfrom.focus();return(false) } } else { document.breakdown.submit(); } } </SCRIPT> </head><body> <form name="breakdown"> <input type="text" name="depositmade" value="y"> <input type="text" name="depositMOfrom" value="mth"> <input type="button" onclick="checkme()" value="Submit"> <input type="reset"> </form> Link to comment https://forums.phpfreaks.com/topic/83392-javascript-conditional-statements-embedded/#findComment-424491 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.