Reputation: 67
I'm trying to create a dual login script that logs a user into two separate systems (form a & form b) from another separate login (dual).
<h2>Dual Login</h2>
<form id="dual">
username<br>
<input type="input" name="un" value="1234567"><br>
password<br><input type="password" name="password"><br>
<input type="submit" name="submit">
</form>
<h2>Login A</h2>
<form id="login_a" action="#" method="post">
username<br>
<input id="un_a" type="input" name="un_a" value="hi"><br>
password<br>
<input id="pw_a" type="password" name="pw_a"><br>
<input type="submit" name="submit">
</form>
<h2>Login B</h2>
<form id="login_b" method="post" action="#">
username 1<br>
<input id="un_b" type="text" name="un_b" value=""><br>
password<br>
<input id="pw_b" type="password" name="pw_b"><br>
<input type="submit">
</form>
Here is the jQuery:
$('#dual :input[name="un"]').blur(function(){
un = $('#dual :input[name="un"]').val();
$('#un_a').val(un);
$('#un_b').val(un);
});
Here is a fiddle that illustrates the working example:
http://jsfiddle.net/mckinselberg/bPapQ/
My question is: Why is it that when I try to update the values this way, it doesn't work:
$('#dual :input[name="un"]').blur(function(){
un = $('#dual :input[name="un"]').val();
$('#form_a :input[name="un_a"]').val(un);
$('#form_b :input[name="un_b"]').val(un);
});
Here is a fiddle that illustrates the non-working example:
http://jsfiddle.net/mckinselberg/BbKTG/
Upvotes: 1
Views: 280
Reputation: 55750
$('#form_a // supposed to be $('#login_a
$('#form_b // supposed to be $('#login_b
Check your id's
<form id="login_a"
<form id="login_b"
It's a simple explanation. You are selecting the wrong id's
Upvotes: 5
Reputation: 63588
Your ID's don't match... you have login_a
in the HTML and form_a
in the jQuery
Upvotes: 1
Reputation: 18891
You were selecting #form_a
and #form_b
, when the ID used on the forms in your HTML is #login_a
and #login_b
respectively. Fiddle: http://jsfiddle.net/BbKTG/3/
Upvotes: 1