Newbie - form question, please help...

Discussion in 'JavaScript' started by kensol, Mar 13, 2008.

  1. #1
    Maybe I'm just stupid, but I can't get this code to work, and can't see what's wrong.

    I am trying to display two text-input fields, with a pop-up alert. If the number in field one is greater than 26,5 and the number in field two is greater than 36, 36 should be subtracted from the number from field two and multiplied with 0,5. The variable "result" should be "alerted" (You should spot the rest).

    Problem is nothing is returned.

    Please help?

    <HTML>
    <HEAD>
    <TITLE>Test Input</TITLE>
    <SCRIPT LANGUAGE="JavaScript">
    function testfunction (form) {
        var formone = form.inputbox.value;
        var formtwo = form.inputbox2.value;
    }
    
    if (formone>26,5) && (formtwo>36);
    {
    var calculationvariable = (formtwo-36)*0,5;
    var result = formone - calculationvariable;
    formtwo=--;
    alert (result);
    }
    
    </SCRIPT>
    </HEAD>
    <BODY>
    <FORM NAME="myform" ACTION="" METHOD="GET">Enter parameter 1: 
    <INPUT TYPE="text" NAME="inputbox" VALUE=""><P>Enter parameter 2:
    <INPUT TYPE="text" NAME="inputbox2" VALUE=""><P>
    <INPUT TYPE="button" NAME="button" Value="Click" onClick="testfunction()">
    </FORM>
    </BODY>
    </HTML>
    Code (markup):
     
    kensol, Mar 13, 2008 IP
  2. rkquest

    rkquest Well-Known Member

    Messages:
    828
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    140
    #2
    You should put the condition inside the function...

    
    <SCRIPT LANGUAGE="JavaScript">
    function testfunction (form) {
    	var formone = form.inputbox.value;
    	var formtwo = form.inputbox2.value;
    	if (formone>26,5) && (formtwo>36);
    	{
    	var calculationvariable = (formtwo-36)*0,5;
    	var result = formone - calculationvariable;
    	formtwo=--;
    	alert (result);
    	}
    }
    </SCRIPT>
    
    Code (markup):
     
    rkquest, Mar 13, 2008 IP