<input type="text" value="" id='a'>
<br>
<input type="button" value="15" id='b'>
<br>
<input type="button" value="" id='c'>
/*query cods*/
$(document).ready(function(){$('#c').click(function(){
a=document.getElementById('a').value;
b=document.getElementById('b').value;
if(a>b){
alert('no')
}
else{
alert('yes')
}
})})
since you didn’t post the HMTL, it could be anything.
@amir1313: you need to format your code to have it show up correctly in your posts.
You can highlight your code, then use the </> button in the editor window, which will format it.
Or you can place three backticks ``` (top left key on US/UK keyboards) on a line before your code, and three on a line after your code. I find this approach easier, but unfortunately some European and other keyboards don’t have that character.
<html>
<input type="text" value=0 id='a'>
<br>
<input type="button" value=15 id='b'>
<br>
<input type="button" value="" id='c'>
</html>
Those values are always strings, not numbers. Try
var a = Number(document.getElementById('a').value);
var b = Number(document.getElementById('b').value);
Is there another thread on this topic or was this thread just edited? I just posted a response about 10 minutes ago to one that had this code:
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<body>
<input type="text" value=0 id='a'>
<br>
<input type="button" value=15 id='b'>
<br>
<input type="button" value="" id='c'>
<script>
$(document).ready(function(){$('#c').click(function(){
a=document.getElementById('a').value;
b=document.getElementById('b').value;
if(a>b){
alert('no')
}
else{
alert('yes')
}
})})
</script>
</body>
</html>
stating that the value of the inputs were strings, but it seems to have disappeared.
Thanks for your help
The ninja nirvana? ^^
Yes there is. I’ll merge the two topics.
@amir1313: please do not start multiple threads on the same subject, as it leads to exactly this kind of confusion.
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<body>
<input type="text" value=0 id='a'>
<br>
<input type="button" value=15 id='b'>
<br>
<input type="button" value="" id='c'>
<script>
$(document).ready(function(){$('#c').click(function(){
a=document.getElementById('a').value;
b=document.getElementById('b').value;
if(a>b){
alert('no')
}
else{
alert('yes')
}
})})
</script>
</body>
</html>
The value of an input is a string, not a number. Would that have an effect on the result of the comparison?
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.