Jquery get input value from another text input value and set into hidden input value










0















I am new at Jquery. My User Story: I have two input form tag. One is hidden and One is Text. I need to take value from input text and set that value into hidden input and then submit the form with both value. Is it possible to do in Jquery. Here is my example code:



if($_POST)
$email = $_REQUEST['email'];
$username = $_REQUEST['username'];

echo "Email Value: " . $email ." And Username Value :" .$username;





var lap = $("emailId").val();
var test = $("userId");
test.val(test);

<form>
<input id="emailId" name="email" type="text" value= "">
<input id="userId" name="username" type="hidden" value="">

<input type="submit" value="Submit" />
</form>












share|improve this question

















  • 1





    Your jQuery id selectors are missing # prefix... var test = $("#userId"); Should work fine with those fixed and test.val(lap)

    – charlietfl
    Nov 13 '18 at 16:34












  • I tried with id selector. Still no luck

    – mike1225
    Nov 13 '18 at 16:36







  • 1





    As well as the # prefixes you need to use test.val(lap). Also note that this logic will only execute when the page loads. If you want to update the value once one is entered you'll need to use an event handler. I'd suggest input.

    – Rory McCrossan
    Nov 13 '18 at 16:37












  • Do you have an example event handler. I am still learning.Please help.

    – mike1225
    Nov 13 '18 at 16:42











  • @mike1225 $('input[type=submit]').on('click', yourFunction) This is event listener on input for click event

    – Smollet777
    Nov 13 '18 at 16:47















0















I am new at Jquery. My User Story: I have two input form tag. One is hidden and One is Text. I need to take value from input text and set that value into hidden input and then submit the form with both value. Is it possible to do in Jquery. Here is my example code:



if($_POST)
$email = $_REQUEST['email'];
$username = $_REQUEST['username'];

echo "Email Value: " . $email ." And Username Value :" .$username;





var lap = $("emailId").val();
var test = $("userId");
test.val(test);

<form>
<input id="emailId" name="email" type="text" value= "">
<input id="userId" name="username" type="hidden" value="">

<input type="submit" value="Submit" />
</form>












share|improve this question

















  • 1





    Your jQuery id selectors are missing # prefix... var test = $("#userId"); Should work fine with those fixed and test.val(lap)

    – charlietfl
    Nov 13 '18 at 16:34












  • I tried with id selector. Still no luck

    – mike1225
    Nov 13 '18 at 16:36







  • 1





    As well as the # prefixes you need to use test.val(lap). Also note that this logic will only execute when the page loads. If you want to update the value once one is entered you'll need to use an event handler. I'd suggest input.

    – Rory McCrossan
    Nov 13 '18 at 16:37












  • Do you have an example event handler. I am still learning.Please help.

    – mike1225
    Nov 13 '18 at 16:42











  • @mike1225 $('input[type=submit]').on('click', yourFunction) This is event listener on input for click event

    – Smollet777
    Nov 13 '18 at 16:47













0












0








0








I am new at Jquery. My User Story: I have two input form tag. One is hidden and One is Text. I need to take value from input text and set that value into hidden input and then submit the form with both value. Is it possible to do in Jquery. Here is my example code:



if($_POST)
$email = $_REQUEST['email'];
$username = $_REQUEST['username'];

echo "Email Value: " . $email ." And Username Value :" .$username;





var lap = $("emailId").val();
var test = $("userId");
test.val(test);

<form>
<input id="emailId" name="email" type="text" value= "">
<input id="userId" name="username" type="hidden" value="">

<input type="submit" value="Submit" />
</form>












share|improve this question














I am new at Jquery. My User Story: I have two input form tag. One is hidden and One is Text. I need to take value from input text and set that value into hidden input and then submit the form with both value. Is it possible to do in Jquery. Here is my example code:



if($_POST)
$email = $_REQUEST['email'];
$username = $_REQUEST['username'];

echo "Email Value: " . $email ." And Username Value :" .$username;





var lap = $("emailId").val();
var test = $("userId");
test.val(test);

<form>
<input id="emailId" name="email" type="text" value= "">
<input id="userId" name="username" type="hidden" value="">

<input type="submit" value="Submit" />
</form>








var lap = $("emailId").val();
var test = $("userId");
test.val(test);

<form>
<input id="emailId" name="email" type="text" value= "">
<input id="userId" name="username" type="hidden" value="">

<input type="submit" value="Submit" />
</form>





var lap = $("emailId").val();
var test = $("userId");
test.val(test);

<form>
<input id="emailId" name="email" type="text" value= "">
<input id="userId" name="username" type="hidden" value="">

<input type="submit" value="Submit" />
</form>






javascript jquery html html5






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 16:31









mike1225mike1225

96




96







  • 1





    Your jQuery id selectors are missing # prefix... var test = $("#userId"); Should work fine with those fixed and test.val(lap)

    – charlietfl
    Nov 13 '18 at 16:34












  • I tried with id selector. Still no luck

    – mike1225
    Nov 13 '18 at 16:36







  • 1





    As well as the # prefixes you need to use test.val(lap). Also note that this logic will only execute when the page loads. If you want to update the value once one is entered you'll need to use an event handler. I'd suggest input.

    – Rory McCrossan
    Nov 13 '18 at 16:37












  • Do you have an example event handler. I am still learning.Please help.

    – mike1225
    Nov 13 '18 at 16:42











  • @mike1225 $('input[type=submit]').on('click', yourFunction) This is event listener on input for click event

    – Smollet777
    Nov 13 '18 at 16:47












  • 1





    Your jQuery id selectors are missing # prefix... var test = $("#userId"); Should work fine with those fixed and test.val(lap)

    – charlietfl
    Nov 13 '18 at 16:34












  • I tried with id selector. Still no luck

    – mike1225
    Nov 13 '18 at 16:36







  • 1





    As well as the # prefixes you need to use test.val(lap). Also note that this logic will only execute when the page loads. If you want to update the value once one is entered you'll need to use an event handler. I'd suggest input.

    – Rory McCrossan
    Nov 13 '18 at 16:37












  • Do you have an example event handler. I am still learning.Please help.

    – mike1225
    Nov 13 '18 at 16:42











  • @mike1225 $('input[type=submit]').on('click', yourFunction) This is event listener on input for click event

    – Smollet777
    Nov 13 '18 at 16:47







1




1





Your jQuery id selectors are missing # prefix... var test = $("#userId"); Should work fine with those fixed and test.val(lap)

– charlietfl
Nov 13 '18 at 16:34






Your jQuery id selectors are missing # prefix... var test = $("#userId"); Should work fine with those fixed and test.val(lap)

– charlietfl
Nov 13 '18 at 16:34














I tried with id selector. Still no luck

– mike1225
Nov 13 '18 at 16:36






I tried with id selector. Still no luck

– mike1225
Nov 13 '18 at 16:36





1




1





As well as the # prefixes you need to use test.val(lap). Also note that this logic will only execute when the page loads. If you want to update the value once one is entered you'll need to use an event handler. I'd suggest input.

– Rory McCrossan
Nov 13 '18 at 16:37






As well as the # prefixes you need to use test.val(lap). Also note that this logic will only execute when the page loads. If you want to update the value once one is entered you'll need to use an event handler. I'd suggest input.

– Rory McCrossan
Nov 13 '18 at 16:37














Do you have an example event handler. I am still learning.Please help.

– mike1225
Nov 13 '18 at 16:42





Do you have an example event handler. I am still learning.Please help.

– mike1225
Nov 13 '18 at 16:42













@mike1225 $('input[type=submit]').on('click', yourFunction) This is event listener on input for click event

– Smollet777
Nov 13 '18 at 16:47





@mike1225 $('input[type=submit]').on('click', yourFunction) This is event listener on input for click event

– Smollet777
Nov 13 '18 at 16:47












2 Answers
2






active

oldest

votes


















1














You don't need jQuery for this. I've provide a solution using jQuery as well as vanilla JavaScript.



jQuery Version






$(document).ready(function()
$email = $('#email')
// Note that we are updating the hidden input value each time the
// text input value changes. We could do this less frequently by
// using the `input` or `change` event instead of the `keyup` event.
$email.on('keyup', function(e)
$('#userId').val($email.val())
);
)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<form>
<input type="text" name="email" id="email" />
<input type="hidden" name="userId" id="userId" />
<button type="submit" id="submit">Submit</button>
</form>





Vanilla JavaScript Version






document.addEventListener('DOMContentLoaded', function(e) 
var txtEmail = document.querySelector('#email')
var txtUserId = document.querySelector('#userId')
// Note that we are updating the hidden input value each time the
// text input value changes. We could do this less frequently by
// using the `input` or `change` event instead of the `keyup` event.
txtEmail.addEventListener('keyup', function(e)
txtUserId.value = txtEmail.value
)
)

<form>
<input type="text" name="email" id="email" />
<input type="hidden" name="userId" id="userId" />
<button type="submit" id="submit">Submit</button>
</form>





A brief explanation of my method



Waiting for the HTML to load



Whether you're using jQuery or not, depending on how your JavaScript and HTML code is stitched together, sometimes you're HTML elements are not available when your JavaScript code runs (for example, if your JavaScript code is included in the <head> tag, which I think has become pretty uncommon these days). For this reason, I've gotten into the habit of making sure the document is ready before I reference any HTML elements. Using jQuery, this is done with the following code:



$(document).ready(function()
// The code here (inside this function) will be executed after the HTML finishes loading.
)


With vanilla JavaScript, the code looks like this:



document.addEventListener('DOMContentLoaded', function()
// The code here (inside this function) will be executed after the HTML finishes loading.
)


Making Updates As Soon As Possible



In addition, my code updates the hidden input value after the text input value has changed, rather than waiting for the form to be submitted. Either option may be perfectly acceptable for a given situation. I am in the habit of updating things like these as soon as possible; if in the future, I write some JavaScript code that is expecting the value of these to input controls to be equivalent, and that code runs before the form is submitted, I'll probably have a bug in my code. Hence, I find it safer to just update as soon as the change occurs.






share|improve this answer
































    0














    As per jquery documentation You forgot to use # in your both selectors. You should use:



    var lap = $("#emailId").val();
    var test = $("#userId");
    test.val(lap);





    share|improve this answer




















    • 2





      test.val(test) is incorrect and would make the value "[object Object"]"

      – charlietfl
      Nov 13 '18 at 16:39












    • Nice job referencing the documentation!

      – Trevor
      Nov 13 '18 at 17:02











    • @Trevor Thank you Sir. I seen the value when I type in the input box in the console, how do I put this value in hidden input and submit the both value

      – mike1225
      Nov 13 '18 at 17:15











    • @mike1225 Look at my answer above (stackoverflow.com/a/53285919/269061). It sets the value of the hidden input automatically, so when you submit the form, the value will already be there.

      – Trevor
      Nov 13 '18 at 17:18











    • Awseome!!! Greatly appreciated it. I almost kills the production.

      – mike1225
      Nov 13 '18 at 17:26










    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53285501%2fjquery-get-input-value-from-another-text-input-value-and-set-into-hidden-input-v%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You don't need jQuery for this. I've provide a solution using jQuery as well as vanilla JavaScript.



    jQuery Version






    $(document).ready(function()
    $email = $('#email')
    // Note that we are updating the hidden input value each time the
    // text input value changes. We could do this less frequently by
    // using the `input` or `change` event instead of the `keyup` event.
    $email.on('keyup', function(e)
    $('#userId').val($email.val())
    );
    )

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

    <form>
    <input type="text" name="email" id="email" />
    <input type="hidden" name="userId" id="userId" />
    <button type="submit" id="submit">Submit</button>
    </form>





    Vanilla JavaScript Version






    document.addEventListener('DOMContentLoaded', function(e) 
    var txtEmail = document.querySelector('#email')
    var txtUserId = document.querySelector('#userId')
    // Note that we are updating the hidden input value each time the
    // text input value changes. We could do this less frequently by
    // using the `input` or `change` event instead of the `keyup` event.
    txtEmail.addEventListener('keyup', function(e)
    txtUserId.value = txtEmail.value
    )
    )

    <form>
    <input type="text" name="email" id="email" />
    <input type="hidden" name="userId" id="userId" />
    <button type="submit" id="submit">Submit</button>
    </form>





    A brief explanation of my method



    Waiting for the HTML to load



    Whether you're using jQuery or not, depending on how your JavaScript and HTML code is stitched together, sometimes you're HTML elements are not available when your JavaScript code runs (for example, if your JavaScript code is included in the <head> tag, which I think has become pretty uncommon these days). For this reason, I've gotten into the habit of making sure the document is ready before I reference any HTML elements. Using jQuery, this is done with the following code:



    $(document).ready(function()
    // The code here (inside this function) will be executed after the HTML finishes loading.
    )


    With vanilla JavaScript, the code looks like this:



    document.addEventListener('DOMContentLoaded', function()
    // The code here (inside this function) will be executed after the HTML finishes loading.
    )


    Making Updates As Soon As Possible



    In addition, my code updates the hidden input value after the text input value has changed, rather than waiting for the form to be submitted. Either option may be perfectly acceptable for a given situation. I am in the habit of updating things like these as soon as possible; if in the future, I write some JavaScript code that is expecting the value of these to input controls to be equivalent, and that code runs before the form is submitted, I'll probably have a bug in my code. Hence, I find it safer to just update as soon as the change occurs.






    share|improve this answer





























      1














      You don't need jQuery for this. I've provide a solution using jQuery as well as vanilla JavaScript.



      jQuery Version






      $(document).ready(function()
      $email = $('#email')
      // Note that we are updating the hidden input value each time the
      // text input value changes. We could do this less frequently by
      // using the `input` or `change` event instead of the `keyup` event.
      $email.on('keyup', function(e)
      $('#userId').val($email.val())
      );
      )

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

      <form>
      <input type="text" name="email" id="email" />
      <input type="hidden" name="userId" id="userId" />
      <button type="submit" id="submit">Submit</button>
      </form>





      Vanilla JavaScript Version






      document.addEventListener('DOMContentLoaded', function(e) 
      var txtEmail = document.querySelector('#email')
      var txtUserId = document.querySelector('#userId')
      // Note that we are updating the hidden input value each time the
      // text input value changes. We could do this less frequently by
      // using the `input` or `change` event instead of the `keyup` event.
      txtEmail.addEventListener('keyup', function(e)
      txtUserId.value = txtEmail.value
      )
      )

      <form>
      <input type="text" name="email" id="email" />
      <input type="hidden" name="userId" id="userId" />
      <button type="submit" id="submit">Submit</button>
      </form>





      A brief explanation of my method



      Waiting for the HTML to load



      Whether you're using jQuery or not, depending on how your JavaScript and HTML code is stitched together, sometimes you're HTML elements are not available when your JavaScript code runs (for example, if your JavaScript code is included in the <head> tag, which I think has become pretty uncommon these days). For this reason, I've gotten into the habit of making sure the document is ready before I reference any HTML elements. Using jQuery, this is done with the following code:



      $(document).ready(function()
      // The code here (inside this function) will be executed after the HTML finishes loading.
      )


      With vanilla JavaScript, the code looks like this:



      document.addEventListener('DOMContentLoaded', function()
      // The code here (inside this function) will be executed after the HTML finishes loading.
      )


      Making Updates As Soon As Possible



      In addition, my code updates the hidden input value after the text input value has changed, rather than waiting for the form to be submitted. Either option may be perfectly acceptable for a given situation. I am in the habit of updating things like these as soon as possible; if in the future, I write some JavaScript code that is expecting the value of these to input controls to be equivalent, and that code runs before the form is submitted, I'll probably have a bug in my code. Hence, I find it safer to just update as soon as the change occurs.






      share|improve this answer



























        1












        1








        1







        You don't need jQuery for this. I've provide a solution using jQuery as well as vanilla JavaScript.



        jQuery Version






        $(document).ready(function()
        $email = $('#email')
        // Note that we are updating the hidden input value each time the
        // text input value changes. We could do this less frequently by
        // using the `input` or `change` event instead of the `keyup` event.
        $email.on('keyup', function(e)
        $('#userId').val($email.val())
        );
        )

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

        <form>
        <input type="text" name="email" id="email" />
        <input type="hidden" name="userId" id="userId" />
        <button type="submit" id="submit">Submit</button>
        </form>





        Vanilla JavaScript Version






        document.addEventListener('DOMContentLoaded', function(e) 
        var txtEmail = document.querySelector('#email')
        var txtUserId = document.querySelector('#userId')
        // Note that we are updating the hidden input value each time the
        // text input value changes. We could do this less frequently by
        // using the `input` or `change` event instead of the `keyup` event.
        txtEmail.addEventListener('keyup', function(e)
        txtUserId.value = txtEmail.value
        )
        )

        <form>
        <input type="text" name="email" id="email" />
        <input type="hidden" name="userId" id="userId" />
        <button type="submit" id="submit">Submit</button>
        </form>





        A brief explanation of my method



        Waiting for the HTML to load



        Whether you're using jQuery or not, depending on how your JavaScript and HTML code is stitched together, sometimes you're HTML elements are not available when your JavaScript code runs (for example, if your JavaScript code is included in the <head> tag, which I think has become pretty uncommon these days). For this reason, I've gotten into the habit of making sure the document is ready before I reference any HTML elements. Using jQuery, this is done with the following code:



        $(document).ready(function()
        // The code here (inside this function) will be executed after the HTML finishes loading.
        )


        With vanilla JavaScript, the code looks like this:



        document.addEventListener('DOMContentLoaded', function()
        // The code here (inside this function) will be executed after the HTML finishes loading.
        )


        Making Updates As Soon As Possible



        In addition, my code updates the hidden input value after the text input value has changed, rather than waiting for the form to be submitted. Either option may be perfectly acceptable for a given situation. I am in the habit of updating things like these as soon as possible; if in the future, I write some JavaScript code that is expecting the value of these to input controls to be equivalent, and that code runs before the form is submitted, I'll probably have a bug in my code. Hence, I find it safer to just update as soon as the change occurs.






        share|improve this answer















        You don't need jQuery for this. I've provide a solution using jQuery as well as vanilla JavaScript.



        jQuery Version






        $(document).ready(function()
        $email = $('#email')
        // Note that we are updating the hidden input value each time the
        // text input value changes. We could do this less frequently by
        // using the `input` or `change` event instead of the `keyup` event.
        $email.on('keyup', function(e)
        $('#userId').val($email.val())
        );
        )

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

        <form>
        <input type="text" name="email" id="email" />
        <input type="hidden" name="userId" id="userId" />
        <button type="submit" id="submit">Submit</button>
        </form>





        Vanilla JavaScript Version






        document.addEventListener('DOMContentLoaded', function(e) 
        var txtEmail = document.querySelector('#email')
        var txtUserId = document.querySelector('#userId')
        // Note that we are updating the hidden input value each time the
        // text input value changes. We could do this less frequently by
        // using the `input` or `change` event instead of the `keyup` event.
        txtEmail.addEventListener('keyup', function(e)
        txtUserId.value = txtEmail.value
        )
        )

        <form>
        <input type="text" name="email" id="email" />
        <input type="hidden" name="userId" id="userId" />
        <button type="submit" id="submit">Submit</button>
        </form>





        A brief explanation of my method



        Waiting for the HTML to load



        Whether you're using jQuery or not, depending on how your JavaScript and HTML code is stitched together, sometimes you're HTML elements are not available when your JavaScript code runs (for example, if your JavaScript code is included in the <head> tag, which I think has become pretty uncommon these days). For this reason, I've gotten into the habit of making sure the document is ready before I reference any HTML elements. Using jQuery, this is done with the following code:



        $(document).ready(function()
        // The code here (inside this function) will be executed after the HTML finishes loading.
        )


        With vanilla JavaScript, the code looks like this:



        document.addEventListener('DOMContentLoaded', function()
        // The code here (inside this function) will be executed after the HTML finishes loading.
        )


        Making Updates As Soon As Possible



        In addition, my code updates the hidden input value after the text input value has changed, rather than waiting for the form to be submitted. Either option may be perfectly acceptable for a given situation. I am in the habit of updating things like these as soon as possible; if in the future, I write some JavaScript code that is expecting the value of these to input controls to be equivalent, and that code runs before the form is submitted, I'll probably have a bug in my code. Hence, I find it safer to just update as soon as the change occurs.






        $(document).ready(function()
        $email = $('#email')
        // Note that we are updating the hidden input value each time the
        // text input value changes. We could do this less frequently by
        // using the `input` or `change` event instead of the `keyup` event.
        $email.on('keyup', function(e)
        $('#userId').val($email.val())
        );
        )

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

        <form>
        <input type="text" name="email" id="email" />
        <input type="hidden" name="userId" id="userId" />
        <button type="submit" id="submit">Submit</button>
        </form>





        $(document).ready(function()
        $email = $('#email')
        // Note that we are updating the hidden input value each time the
        // text input value changes. We could do this less frequently by
        // using the `input` or `change` event instead of the `keyup` event.
        $email.on('keyup', function(e)
        $('#userId').val($email.val())
        );
        )

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

        <form>
        <input type="text" name="email" id="email" />
        <input type="hidden" name="userId" id="userId" />
        <button type="submit" id="submit">Submit</button>
        </form>





        document.addEventListener('DOMContentLoaded', function(e) 
        var txtEmail = document.querySelector('#email')
        var txtUserId = document.querySelector('#userId')
        // Note that we are updating the hidden input value each time the
        // text input value changes. We could do this less frequently by
        // using the `input` or `change` event instead of the `keyup` event.
        txtEmail.addEventListener('keyup', function(e)
        txtUserId.value = txtEmail.value
        )
        )

        <form>
        <input type="text" name="email" id="email" />
        <input type="hidden" name="userId" id="userId" />
        <button type="submit" id="submit">Submit</button>
        </form>





        document.addEventListener('DOMContentLoaded', function(e) 
        var txtEmail = document.querySelector('#email')
        var txtUserId = document.querySelector('#userId')
        // Note that we are updating the hidden input value each time the
        // text input value changes. We could do this less frequently by
        // using the `input` or `change` event instead of the `keyup` event.
        txtEmail.addEventListener('keyup', function(e)
        txtUserId.value = txtEmail.value
        )
        )

        <form>
        <input type="text" name="email" id="email" />
        <input type="hidden" name="userId" id="userId" />
        <button type="submit" id="submit">Submit</button>
        </form>






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 13 '18 at 17:12

























        answered Nov 13 '18 at 16:53









        TrevorTrevor

        7,17195681




        7,17195681























            0














            As per jquery documentation You forgot to use # in your both selectors. You should use:



            var lap = $("#emailId").val();
            var test = $("#userId");
            test.val(lap);





            share|improve this answer




















            • 2





              test.val(test) is incorrect and would make the value "[object Object"]"

              – charlietfl
              Nov 13 '18 at 16:39












            • Nice job referencing the documentation!

              – Trevor
              Nov 13 '18 at 17:02











            • @Trevor Thank you Sir. I seen the value when I type in the input box in the console, how do I put this value in hidden input and submit the both value

              – mike1225
              Nov 13 '18 at 17:15











            • @mike1225 Look at my answer above (stackoverflow.com/a/53285919/269061). It sets the value of the hidden input automatically, so when you submit the form, the value will already be there.

              – Trevor
              Nov 13 '18 at 17:18











            • Awseome!!! Greatly appreciated it. I almost kills the production.

              – mike1225
              Nov 13 '18 at 17:26















            0














            As per jquery documentation You forgot to use # in your both selectors. You should use:



            var lap = $("#emailId").val();
            var test = $("#userId");
            test.val(lap);





            share|improve this answer




















            • 2





              test.val(test) is incorrect and would make the value "[object Object"]"

              – charlietfl
              Nov 13 '18 at 16:39












            • Nice job referencing the documentation!

              – Trevor
              Nov 13 '18 at 17:02











            • @Trevor Thank you Sir. I seen the value when I type in the input box in the console, how do I put this value in hidden input and submit the both value

              – mike1225
              Nov 13 '18 at 17:15











            • @mike1225 Look at my answer above (stackoverflow.com/a/53285919/269061). It sets the value of the hidden input automatically, so when you submit the form, the value will already be there.

              – Trevor
              Nov 13 '18 at 17:18











            • Awseome!!! Greatly appreciated it. I almost kills the production.

              – mike1225
              Nov 13 '18 at 17:26













            0












            0








            0







            As per jquery documentation You forgot to use # in your both selectors. You should use:



            var lap = $("#emailId").val();
            var test = $("#userId");
            test.val(lap);





            share|improve this answer















            As per jquery documentation You forgot to use # in your both selectors. You should use:



            var lap = $("#emailId").val();
            var test = $("#userId");
            test.val(lap);






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 13 '18 at 17:00









            Trevor

            7,17195681




            7,17195681










            answered Nov 13 '18 at 16:38









            dganencodganenco

            2077




            2077







            • 2





              test.val(test) is incorrect and would make the value "[object Object"]"

              – charlietfl
              Nov 13 '18 at 16:39












            • Nice job referencing the documentation!

              – Trevor
              Nov 13 '18 at 17:02











            • @Trevor Thank you Sir. I seen the value when I type in the input box in the console, how do I put this value in hidden input and submit the both value

              – mike1225
              Nov 13 '18 at 17:15











            • @mike1225 Look at my answer above (stackoverflow.com/a/53285919/269061). It sets the value of the hidden input automatically, so when you submit the form, the value will already be there.

              – Trevor
              Nov 13 '18 at 17:18











            • Awseome!!! Greatly appreciated it. I almost kills the production.

              – mike1225
              Nov 13 '18 at 17:26












            • 2





              test.val(test) is incorrect and would make the value "[object Object"]"

              – charlietfl
              Nov 13 '18 at 16:39












            • Nice job referencing the documentation!

              – Trevor
              Nov 13 '18 at 17:02











            • @Trevor Thank you Sir. I seen the value when I type in the input box in the console, how do I put this value in hidden input and submit the both value

              – mike1225
              Nov 13 '18 at 17:15











            • @mike1225 Look at my answer above (stackoverflow.com/a/53285919/269061). It sets the value of the hidden input automatically, so when you submit the form, the value will already be there.

              – Trevor
              Nov 13 '18 at 17:18











            • Awseome!!! Greatly appreciated it. I almost kills the production.

              – mike1225
              Nov 13 '18 at 17:26







            2




            2





            test.val(test) is incorrect and would make the value "[object Object"]"

            – charlietfl
            Nov 13 '18 at 16:39






            test.val(test) is incorrect and would make the value "[object Object"]"

            – charlietfl
            Nov 13 '18 at 16:39














            Nice job referencing the documentation!

            – Trevor
            Nov 13 '18 at 17:02





            Nice job referencing the documentation!

            – Trevor
            Nov 13 '18 at 17:02













            @Trevor Thank you Sir. I seen the value when I type in the input box in the console, how do I put this value in hidden input and submit the both value

            – mike1225
            Nov 13 '18 at 17:15





            @Trevor Thank you Sir. I seen the value when I type in the input box in the console, how do I put this value in hidden input and submit the both value

            – mike1225
            Nov 13 '18 at 17:15













            @mike1225 Look at my answer above (stackoverflow.com/a/53285919/269061). It sets the value of the hidden input automatically, so when you submit the form, the value will already be there.

            – Trevor
            Nov 13 '18 at 17:18





            @mike1225 Look at my answer above (stackoverflow.com/a/53285919/269061). It sets the value of the hidden input automatically, so when you submit the form, the value will already be there.

            – Trevor
            Nov 13 '18 at 17:18













            Awseome!!! Greatly appreciated it. I almost kills the production.

            – mike1225
            Nov 13 '18 at 17:26





            Awseome!!! Greatly appreciated it. I almost kills the production.

            – mike1225
            Nov 13 '18 at 17:26

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53285501%2fjquery-get-input-value-from-another-text-input-value-and-set-into-hidden-input-v%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            政党

            天津地下鉄3号線