www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] document.form... help

  1. #1
    Join Date
    Sep 2005
    Posts
    31

    resolved [RESOLVED] document.form... help

    Hello all,

    Been a long time since I've been here, glad to be back.

    I have a form that I'd like to post up on my site for my my staff to keep track of how much they're donating. And then based on the value or answer for their form, whether their answer is =, > or <, then a respective IF or ELSE statement would be called.


    I can code decent IF and ELSE statements....but not when incorporating forms or form results. Without using the form, I have the script working just fine, but I cannot fix it otherwise.

    Here's the code and form that I have right now. Also, please disregard anything in the // comments, that's what I used without the form.

    Code:
    <script type="text/javascript">
    function formanswer(){
    
    //var a = 25;
    
    //if(a == 25)
    if (document.form1.submit == 25)
    document.write("You have met your goal of 25!");
    
    //else if(a > 25)
    else if (document.form1.submit > 25)
    document.write("You have exceeded your goal of 25.");
    
    //else if (a < 25)
    else if (document.form1.submit < 25)
    document.write("You have not met your goal of 25.");
    }
    </script>
    
    
    
    <form name="form1" method="post">
    	<p>How much do you have so far? <input type="text" name="amount" size="20">
    	<input type="submit" value="CALCULATE" name="submit" onclick="JavaScript:return formanswer();">
    	</p>
    </form>
    I appreciate your help in advance.

    Andrew

  2. #2
    Join Date
    Sep 2005
    Posts
    31
    My apologies. I found the answer. It was the form name reference that was the problem.

    Code:
    function formanswer(){
    
    var a = 25;
    
    //if(a == 25)
    if (document.form1.give.value == 25)
    document.write("You have met your goal of " +a+ "!");
    
    //else if(a > 25)
    else if (document.form1.give.value > 25)
    document.write("You have exceeded your goal of 25.");
    
    //else if (a < 25)
    else if (document.form1.give.value < 25)
    document.write("You have not met your goal of 25.");
    
    else if (document.form1.give.value < 5)
    document.write("You are way below goal.");
    
    else if (document.form1.give.value >30)
    document.write("You are way above goal.");
    Now I'd like to figure out how to get it to call the else if, if the value they submit is way above or below.

  3. #3
    Join Date
    Sep 2005
    Posts
    31
    I've found the answer. Although no help was necessary, perhaps this topic can be useful to others in a similar situation...if else, it can be locked and closed.

    Code:
    function formanswer(){
    
    var z  = 136;
    var a  = 25;
    var f  = document.form1.give.value;
    
    
    if (f == 25)
    document.write("Your donation of $<b>" +f+ "</b> has met your goal of 25 exactly.");
    
    else if (f >= 26 && f < z)
    document.write("Your donation of $<b>" +f+ "</b> has exceeded your goal of " +a+ ".");
    
    else if (f <= 24 && f >= 1)
    document.write("Your donation of $<b>" +f+ "</b> has not met your goal of " +a+ ".");
    
    else if (f == z)
    document.write("Your donation of $<b>" +f+ "</b> has met the goal requirements for both the domain and hosting of $136.");
    
    else if (f >= z)
    document.write("Your donation of $<b>" +f+ "</b> has exceeded the goal requirements for both the domain and hosting of $136.");
    
    else if (f == 0)
    document.write("The donation of $<b>" +f+ "</b> is not possible. Please try again.");
    
    else if (f < 0)
    document.write("Not a valid donation value. Please try again.");
    
    }
    Thanks. Andrew

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles