Jump to content

JavaScript Conditional Statements (embedded)


bsamson

Recommended Posts

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?

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.