guyhautier Posted March 9, 2014 Share Posted March 9, 2014 (edited) Hello, Can somebody help me to write a javascript that drives two numbers asks the user. The two numbers compare with each other and allow javascript determine the number entered is greatest. Thank you for helping. Guy Hautier. Edited March 9, 2014 by guyhautier Link to comment Share on other sites More sharing options...
es131245 Posted March 9, 2014 Share Posted March 9, 2014 <!DOCTYPE html><html><body><input type="text" id="first" value="0" /><input type="text" id="second" value="2" /><input type="button" onclick="check()" /><script>function check(){if( parseInt(document.getElementById('first').value) > parseInt(document.getElementById('second').value) ) alert('1>2');else alert('2>1');}</script></body></html> Link to comment Share on other sites More sharing options...
guyhautier Posted March 9, 2014 Author Share Posted March 9, 2014 Thank you for your reply. But the answer must be here as above! Link to comment Share on other sites More sharing options...
davej Posted March 9, 2014 Share Posted March 9, 2014 <!DOCTYPE html><html><head><meta charset="utf-8"><title>tab</title><script>window.onload = function(){ document.getElementById('btn1').onclick = check; }function check(){var a = Number(document.getElementById('a').value);var b = Number(document.getElementById('b').value);// Number() is very similar to parseFloat()var out1 = document.getElementById('out1');var out2 = document.getElementById('out2');var out3 = document.getElementById('out3');if(a< { out1.innerHTML = 'true'; }else{ out1.innerHTML = 'false'; } if(a> { out2.innerHTML = 'true'; }else{ out2.innerHTML = 'false'; } if(a== { out3.innerHTML = 'true'; }else{ out3.innerHTML = 'false'; } }</script></head><body>A:<input type="text" id="a" /> B:<input type="text" id="b" /><input type="button" value="Test" id="btn1" /><hr/>A<B ? <span id="out1"></span><br/>A>B ? <span id="out2"></span><br/>A=B ? <span id="out3"></span></body></html> Link to comment Share on other sites More sharing options...
thescientist Posted March 11, 2014 Share Posted March 11, 2014 we're doing people's homework now? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now