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?

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.