+ 29
how to compare to input string in html
.
12 RĂ©ponses
+ 17
My mistake questions is that how to compare values of two html text input... ?
+ 16
Tysmđđ
+ 9
"How to compare values of two HTML text inputs?"
You could use JS to process the inputs.
Sample Code:-
âââââââââ
HTML:
-----------
<p>Text 1: <input id="text1" type="text"></p>
<p>Text 2: <input id="text2" type="text"></p>
<p><button onclick="compareText()">Compare</button></p>
JS:
-----
function compareText() {
var text1 = document.getElementById("text1").value;
var text2 = document.getElementById("text2").value;
if (text1 == text2) {
alert("Same Text!");
} else {
alert("Different Texts.");
}
}
Code: https://code.sololearn.com/WbyjSW34M4u2/?ref=app
+ 8
I was thinking you were asking how to compare two html documents and was suggesting that you use a diff tool but it seems like you are asking about comparing two html elements programmatically, the solution to which has already been provided.
+ 7
Jerry Glad I could help. Please update the question. Here's how:
1. The first line of my answer has the corrected question. REPLACE your question text with that.
2. Please add the TAGS "html", "compare", and "input" in the question. This helps drive the right users to this question.
3. Mark the question solved by either writing "[SOLVED]" before the question text or marking an answer as the best answer (using the tick mark). This helps users know that your problem has been solved.
+ 5
This question is not understandable to me. Maybe it should be: "How to compare values of two HTML text inputs?"?
+ 5
Jerry Please update the question. I had mentioned the steps in my second answer.
+ 4
Jerry you can also do it like this but if you will like I could do a code tutorial on it
<html>
<head>
<script>
function checks(){
var a =document.getElementById("name1").value;
var b=doucment .getElementById("name2").value;
alert(a==b);
}
</script>
</head>
<body>
<label for="name1">name1</label>
<input id="name1" />
<label for="name2"/></label>
<input id="name2"/>
<button onclick="checks()">Check</button>
</body>
</html>
+ 3
Ok. I was stuck on this myself. But why html (just java or javascript compare) but make sure to assign a hash to the string if your gonna use the results in a list or data parsing because you may say
String a = "string"
String b = "string"
But if you compare a to b......they are two different OBJECTS.
Even if you clone or copy the string like
String b = a
It just copies a and gives it the same value but in a separate OBJECT
Even using the compare class or != or == or < or > etc ..... will ...EVEN IF A IS "HEY THERE" and B IS A COPY OF A THAT IS STORING "HEY THERE".
I tried using char to break up the string and compare strings that way......no.
I finally had to use scanner class to read in the values ..... actually - sorry there is actually more than one way to skin this cat.....I think you can also use string builder class to do this to.
I cant remember but if you really wanna know I'll find my solution.
Back to html...... I think you should use html for UI layout but the backend stuff in other.
+ 1
Comparing does not yield the matching criteria, then how to flag that? can it be related to this question.