Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my code return the error "missing : after property id" in JavaScript?

How is this supposed to be written so that it would actually work?

saveBuyerInfo( 
    { 'save_'+$("#textAreaXMLPostRequest").attr('name') :
    $("#textAreaXMLPostRequest").val() } );
like image 374
thirsty93 Avatar asked Mar 01 '23 21:03

thirsty93


1 Answers

You can't have an expression as the key in an object literal. Instead, create your object first:

var save = {};
save['save_' + $("#textAreaXMLPostRequest").attr('name')] = $("#textAreaXMLPostRequest").val();
saveBuyerInfo(save);
like image 98
Ben Blank Avatar answered Mar 10 '23 11:03

Ben Blank