input value being passed

I have 2 divs on one page.  I have two input fields in the first div and a button. after you have enter the info you press a button and it hides that div and shows the next one. Inside this div I have a dropdown and the 2 hidden fields that I want to get the values from the 2 input fields from the first div.

<div id="welcome">
        <input type="text" id="loginnumber" name="Loginnumber" placeholder="Number" required="required">
        <br>
        <br>
        <input type="text" id="loginname" name="Loginname" placeholder="Name" required="required">
        <br>
        <br>
        <input type="image" src="button.jpg" alt="" class="login-welcome" />
</div>
<div id="form" style="display:none">
    <form name="login-form" method="post" id="login-form" autocomplete='off' action="<?php echo $action; ?>">
        <input type="hidden" name="number" id="number" value="">
        <input type="hidden" name="name" id="name" value="">
        <select>
            <option>1</option>
            <option>2</option>
            <option>3</option>
        </select>
        <br>
        <br>
        <input type="image" src="button.jpg" name="submit" alt="" class="connectButton" />
    </form>
</div>
<script type="text/javascript">
$(document).ready(function () {
    $('.login-welcome').click(function () {
        $("#welcome").hide();
        $("#form").show();
    });

    $('.connectButton').click(function () {
        $('#pack_list').hide();
        $('#progress').fadeIn();

        if ($('#login-form').valid()) {
            $('.connectButton').addClass('grey');
            $('.connectButton').fadeOut(function () {
                $('#form').hide();
            });
        }
    });
});
</script>

Open in new window

ucohockeyAsked:
Who is Participating?
 
Brian TaoSenior Business Solutions ConsultantCommented:
Just add 2 lines to your $('.login-welcome').click() call.  The resulted code then should look like this:
    $('.login-welcome').click(function () {
        $("#welcome").hide();
        $("#form").show();
        $("#number").val($("#loginnumber").val());
        $("#name").val($("#loginname").val());
    });

Open in new window

0
 
Ray PaseurCommented:
This is the sort of thing that is perfect for AngularJS -- two-way data binding!
0
 
ucohockeyAuthor Commented:
I would like to do this without having to load anything, I looked at this solution and might work but would like to see it done using jquery if possible.
0
 
Ray PaseurCommented:
If you want to do this with jQuery, this snippet shows the general design pattern.
http://iconoun.com/demo/temp_ucohockey.php

<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
<meta charset="utf-8" />
<meta name="robots" content="noindex, nofollow" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<style type="text/css">
/* STYLE SHEET HERE */
</style>

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
$(document).ready(function(){
    $('#loginNumber').focus();
    $('#loginWelcome').click(function(){
        var myNumber = $("#loginNumber").val();
        $("#number").val(myNumber);
        $("#welcome").hide();
        $("#form").show();
    });

});
</script>

<title>HTML5 Page With jQuery in UTF-8 Encoding</title>
</head>
<body>

<noscript>Your browsing experience will be much better with JavaScript enabled!</noscript>

<div id="welcome">
Welcome, Enter a number:
        <input type="text" id="loginNumber" name="whatever" placeholder="Number" required="required" />
        <input type="submit" value="clickMe" id="loginWelcome" />
</div>

<div id="form" style="display:none">
Form
        <input type="text" name="number" id="number" value="" />
</div>

</body>
</html>

Open in new window

0
 
Ray PaseurCommented:
Either way you have to "load" something - either the AngularJS library or the jQuery library,  You could probably write your own native JavaScript but most of us would not do that today, since there are so many good frameworks out there.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.