1

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/

1
  • Your fiddle contains no such element, #form_a, or #form_b Commented May 18, 2013 at 1:32

3 Answers 3

5
$('#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

Check Fiddle

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I thought I'd checked it thoroughly. (sound of head slamming against desk)
1

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/

Comments

1

Your ID's don't match... you have login_a in the HTML and form_a in the jQuery

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.