Reputation: 1279
<input id="e-1" type="text"/>
<input id="e-2" type="text"/>
<button id="go">go</button>
This is input validate:
$(document).ready(function(){
var code ="";
var c1="";
var c2="";
$('input#e-1').bind('blur keyup',function() {
c1 = "Error 400 - " + $('input#e-1').val();
});
$('input#e-2').bind('blur keyup',function() {
c2 = "Error 404 - " + $('input#e-2').val();
});
});
How to collect values from all Inputs in a var code ="";
and then display this value by clicking a button to <textarea></textarea>
?
I made a mistake, and how to make different signatures for each line, but not everywhere Error 400? check updated code
Upvotes: 1
Views: 274
Reputation: 38140
Take a look at the jQuery data feature: http://api.jquery.com/jQuery.data/
$(document).ready(function(){
$('input').bind('blur keyup',function() {
$(this).data('my-error-codes', "Error " + $(this).data('error-name') + "- " + $(this).val());
});
$('#go').click(function(){
var code = "";
$("input").each(function(){
code += $(this).data('my-error-codes') + "\n" || '';
});
$('#textarea').html(code);
});
});
Html:
<textarea id="textarea"></textarea>
<input id="e-1" type="text" data-error-name="400" />
<input id="e-2" type="text" data-error-name="404" />
<button id="go">go</button>
JsBin: http://jsbin.com/ubomeq/
http://jsbin.com/ubomeq/edit#source
Upvotes: 1
Reputation: 11028
try this-
<textarea id="textarea"></textarea>
$(document).ready(function(){
var code ="";
$('input#e-1').bind('blur keyup',function() {
code += "Error 400 - " + $('input#e-1').val();
});
$('input#e-2').bind('blur keyup',function() {
code += "Error 400 - " + $('input#e-2').val();
});
$('#go').click(function(){
$('#textarea').html(code);
});
});
Upvotes: 0