简体   繁体   中英

val() returns [object Object]

Here is my script

<input type="text" id="teamleader-default" value="${foo.teamLeaderId}/${foo.teamLeaderFirstName} ${foo.teamLeaderLastName}" />

<script type="text/javascript">
$(document).ready(function(){ 
var teamleader = $('#teamleader-default').val();
var tl_details = teamleader.split("/");

$('#teamleader-default').prop('type', 'hidden');

$("#update").submit(function() {

    if ($('#ParentDD :selected').text() == "Engineer") {
        var tmp0 = $('#teamleader').val(tl_details[1]);
        var tmp1 = $('#teamleaderId').val(tl_details[0]);
        alert(tmp0);
        alert(tmp1);
    } else {
        var tmp2 = $('#teamleader').val('');
        var tmp3 = $('#teamleaderId').val(0);
        alert(tmp2);
        alert(tmp3);
    }
});
});
</script>

The problem is that I can't assign a value for both the teamleader and the teamleader ID

        $('#teamleader').val(tl_details[1]);
        $('#teamleaderId').val(tl_details[0]);

instead the value it contains is just saying "Object object" like the one in this image:

在此处输入图片说明

Can anyone help me on how to assign a value for the team leader.

Again a big thanks for those who could help me.

I think the comments above have already answered the question quite well, if you want to know whether it is assgined successfully, you can use tm0.val() .

By the way, using alert is not my choice to debug code like Js. Since you have chosen Chrome, you can get the advanced debug tool just press F12 .You can get some tips on How to use Chrome DevTools

Happy coding~

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM