JavaScript jQuery returning [object Object] values (Mirroring values of a text input field) jquery returning object object,jquery not returning object,jquery returning

I have 4 inputs in a single form:
1 - Name
2 - First Name
3 - Last Name
4 - Staff Name (Hidden input)

I need to mirror the values inside Name text field onto the Staff Name text field everytime the Name input is updated/changed. I need the changes to reflect in real time and I'm able to achieve this with my code.

The problem I'm having is: I need to check if Name input exists or not, and if not -- to use First Name and Last Name input values instead.

I'm able to successfully mirror Name text values, but during instances when the code has to use First Name and Last Name values, the values being mirrored show up as: [object Object]

I'm completely lost because console.log() shows the correct results.

Below is the code I'm using:

$( document ).ready(function() {
    jQuery.fn.existsWithValue = function() { 
        return this.length && this.val().length; 
    }

    var name_field = $('form[name="card_form"] input[placeholder="Name"]');

    // Function that mirrors the "Staff Name" and "Name" fields everytime the "Name" field is updated
    // Mirrors "Name", "First Name" or "Last Name" inputs, depending on what input exists...
    $('form[name="card_form"] input[placeholder="Name"], form[name="card_form"] input[placeholder="First Name"], form[name="card_form"] input[placeholder="Last Name"]').bind('keyup change', function(e) {

      if ($(name_field).existsWithValue()) {
        // "Name" input exists, mirror "Name" input value:
        var name_field_final = $('form[name="card_form"] input[placeholder="Name"]').val();
      } else {
        // "Name" input does not exist, mirror "First Name" and "Last Name" input values:
        var first_name = $('form[name="card_form"] input[placeholder="First Name"]').val();
        var last_name = $('form[name="card_form"] input[placeholder="Last Name"]').val();

        var name_field_final = first_name + ' ' + last_name;
      }

      // MIRROR VALUES in "Staff" input:
      $('form[name="card_form"] input[name="staff"]').attr("value", $(name_field_final));

      // DEBUG
      console.log( first_name + " : " + last_name );
    });
  });
Answer:1

Problem appears to be caused from setting attribute with an object as value when attributes can only be strings. Also best to set the value property using val()

Change

 // MIRROR VALUES in "Staff" input:
  $('form[name="card_form"] input[name="staff"]').attr("value", $(name_field_final));

to

 // MIRROR VALUES in "Staff" input:
  $('form[name="card_form"] input[name="staff"]').val(name_field_final);
Answer:2

I am busy working with some code that is responing in an unexpected way (to me). It involves handling Node.js promise exceptions. I have the following function modified so that all it does is fail ...

I am busy working with some code that is responing in an unexpected way (to me). It involves handling Node.js promise exceptions. I have the following function modified so that all it does is fail ...

  1. node await catch exception
  2. node await catch
  3. node await catch error
  4. node await try catch
  5. node js await catch error
  6. node async await catch error
  7. node js await catch
  8. node async await catch
  9. node await then catch
  10. node js async await catch
  11. node async await try catch
  12. node js await try catch

I am trying to upload-file using angularFileUpload in php,but i will get this error in angular. [$injector:unpr] Unknown provider: $uploadProvider I have tried answer from this question but no ...

I am trying to upload-file using angularFileUpload in php,but i will get this error in angular. [$injector:unpr] Unknown provider: $uploadProvider I have tried answer from this question but no ...

  1. angularjs file uploading
  2. angularjs file upload example
  3. angularjs file upload example jsfiddle
  4. angularjs file upload formdata
  5. angularjs file upload tutorial
  6. angularjs file upload with progress
  7. angularjs file upload validation
  8. angularjs file upload directive
  9. angularjs file upload example plunker
  10. angularjs file upload get path
  11. angularjs file upload drag and drop
  12. angularjs file upload get filename
  13. angularjs file upload progress bar
  14. angularjs file upload max size
  15. angularjs file upload with form data
  16. angularjs file upload progress bar example
  17. angularjs file upload w3schools
  18. angularjs file upload base64
  19. angularjs file upload ng-change
  20. angularjs file upload size validation

function myFunc(){ console.log(myFunc.message); } myFunc.message = "Hi John"; myFunc(); Executing the above results in - Answer: 'Hi John' How is the function myFunc have the property message ...

function myFunc(){ console.log(myFunc.message); } myFunc.message = "Hi John"; myFunc(); Executing the above results in - Answer: 'Hi John' How is the function myFunc have the property message ...

  1. javascript functions have arguments
  2. do javascript functions have to return a value
  3. javascript can functions have properties
  4. functions have javascript

Say I have a Class Library containing a HelloWorld.js file. This file contains a couple javascript functions, like say: function Hello_alert() { alert("Hello World!!"); } and function ...

Say I have a Class Library containing a HelloWorld.js file. This file contains a couple javascript functions, like say: function Hello_alert() { alert("Hello World!!"); } and function ...

  1. javascript using files
  2. using multiple javascript files
  3. using javascript files in html
  4. using gzip javascript files
  5. using javascript external files
  6. javascript and files
  7. angular use javascript files
  8. using javascript in pdf files