I have 5 input box, and each input box Have a different value .. how i can merge the value of the input boxes and pare it, then alert or do something ..
Example:
<form>
<input id="input1" type="text">
<input id ="input2" type = "text"/>
<input id ="input3" type = "text"/>
<input id = "input4" type = "text"/>
<input id = "input5" type = "text"/>
</form>
var input1 = document.getElementById('input1').value;
var input2 = document.getElementById('input2').value;
var input3 = document.getElementById('input3').value;
var input4 = document.getElementById('input4').value;
var input5 = document.getElementById('input5').value;
var wordsConcat = input1.concat(input2,input3,input4,input5);
//after merging Compare the words to SAMPLE;
I have 5 input box, and each input box Have a different value .. how i can merge the value of the input boxes and pare it, then alert or do something ..
Example:
<form>
<input id="input1" type="text">
<input id ="input2" type = "text"/>
<input id ="input3" type = "text"/>
<input id = "input4" type = "text"/>
<input id = "input5" type = "text"/>
</form>
var input1 = document.getElementById('input1').value;
var input2 = document.getElementById('input2').value;
var input3 = document.getElementById('input3').value;
var input4 = document.getElementById('input4').value;
var input5 = document.getElementById('input5').value;
var wordsConcat = input1.concat(input2,input3,input4,input5);
//after merging Compare the words to SAMPLE;
Share Improve this question edited Feb 10, 2014 at 13:31 Praveen 56.5k35 gold badges136 silver badges165 bronze badges asked Feb 10, 2014 at 13:29 VLDCNDNVLDCNDN 6921 gold badge7 silver badges20 bronze badges 2- loop them and read the values...What have you tried. What do you mean by merge? – epascarello Commented Feb 10, 2014 at 13:30
- pare in the sense if present in wordsconcat or the entire concatinated word is sample??? – Green Wizard Commented Feb 10, 2014 at 13:32
5 Answers
Reset to default 9You've tagged jQuery so I'm assuming it's available to you.
You can map each input to a value, and then join()
them together using an empty string:
var vals = $('input').map(function(){
return this.value;
}).get().join('');
JSFiddle
ES6:
const vals = $('input').map((_, elem) => elem.value).get().join('');
You can do it using each()
method in jQuery
var a='';
$('input[type=text]').each(function(){
a+=this.value;
});
if (a === "SAMPLE") {
//do something
}
Fiddle Demo
var sample = 'your word';
if(wordsConcat === sample){
alert('a');
}
You can try this.
var inputs = document.getElementsByTagName("input"),
inputValue = "";
for (var index=0; index < inputs.length; index ++ ) {
inputValue += inputs[index].value;
}
if (inputValue === "SAMPLE") {
//do something
}
var result = $('input[type="text"]').map(function(i, e){
return e.value;
}).get();
//do pare stuff on result