Using Javascript to compare two input numbers in HTML?

Discussion in 'JavaScript Forum' started by empormike, Apr 10, 2013.

  1. empormike

    empormike New Member

    I am using Notepad++ to create a simple web page where a user types in two numbers into a text box, and then presses a button. When they press the button something comes up that tells them whether the first or second number is greater. I have the following code but cant get anything to come up. Does anyone know whats wrong? \[code\]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><meta http-equiv="content-type" content="text/html;charset=utf-8" /> <title>Assignment 10 Form</title> <script type="text/javascript"> function greaterNum(){ var value1; var value2; value1 = document.First_num.value; value2 = document.last_num.value; if (value1 > value2){ alert('Value 1 is greater than value 2'); document.body.style.background = "orange"; } }</script> <style type="text/css"> body{background-color: #40FF00; margin-left: auto; margin-right: auto; width: 60%; }#container{ border: 2px solid yellow; padding: 20px; }</style></head><body><h1>Assignment 10</h1><div id="container"> <div class="Num"> <form><label class="label1">Enter Value 1:</label><input type="text" name="First_num" value="http://stackoverflow.com/questions/15914514/" /><label class="label1">Enter Value 2:</label><input type="text" name="last_num" value="http://stackoverflow.com/questions/15914514/" /><br/><input type="button" value="http://stackoverflow.com/questions/15914514/Which number is greater?" onclick="greaterNum();" /></form></body></html>\[/code\]
     

Share This Page