Click here to Skip to main content
16,016,168 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I want to compare two variables in jQuery, but I do not.
Where is the problem with your comment

Java
$(document).ready(function(){
var x=document.getElementById("demo")
x.innerHTML=Math.floor((Math.random()*52)*01087);
});
function valid(){
	var x=document.getElementById("demo");
	var y=document.getElementById("txtcode");
	if(x==y)
	{alert("ok");
	return false;
	}
	else
	{alert("nok");
	return false;
	}
	}
Posted
Updated 4-Apr-20 4:28am
Comments
sri senthil kumar 15-Mar-13 6:55am    
Your checking two object i think thats the issue... What you want to compare and what control(div, textbox, hiddenfield etc.,) is that?
bcsilent 15-Mar-13 6:57am    
Thank you dear friend:
Yes two text box fields
Sergey Alexandrovich Kryukov 17-Mar-13 0:20am    
Please don't post non-answers as "solution". It can give you abuse reports which eventually may lead to cancellation of your CodeProject membership. And the fact you even self-accepted on formally is just outrageous, a sure way for a ban. I hope you won't do it after this warning.

Comment on any posts, reply to available comments, or use "Improve question" (above).
Also, keep in mind that members only get notifications on the post sent in reply to there posts.
—SA

C#
var x=document.getElementById("demo").value;
var y=document.getElementById("txtcode").value;
 
Share this answer
 
You may have to convert them to int firstly.
like,
var value = parseInt(valueToConvert);
or
var value= parseFloat(valueToConvert);



then try comparison
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900