MrBliz
MrBliz

Reputation: 5918

Escaping single-quotes javascript

I think the below problem is something to do with escaping strings, but i'm hoping someone will confirm that.

i need to append event.id to the submit value like so: /Events/Edit/ + event.id. There is definitely content in the event.id property as it displays correctly the second time i use it.

$('.ui-dialog div.ui-dialog-buttonpane')
    .append('<button type="submit" value="/Events/Edit/"'  
            + event.id 
            + ' class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" ><span class="ui-button-text">' 
            + event.id + '</span></button>');

Upvotes: 0

Views: 645

Answers (3)

Justin Niessner
Justin Niessner

Reputation: 245489

You just need to move the double quote to after you append the event id (broke things up a little more to make it more readable):

$('.ui-dialog div.ui-dialog-buttonpane')
    .append('<button type="submit" value="/Events/Edit/'
        + event.id 
        + '" class="ui-button ui-widget ui-state-default '
        + 'ui-corner-all ui-button-text-only" ><span class="ui-button-text">' 
        + event.id + '</span></button>');

Upvotes: 2

Matthew Wilson
Matthew Wilson

Reputation: 3929

Move the " forward to after event.id:

$('.ui-dialog div.ui-dialog-buttonpane').append('<button type="submit" value="/Events/Edit/'  + event.id + '" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" ><span class="ui-button-text">' + event.id + '</span></button>');

Upvotes: 1

dave
dave

Reputation: 12806

i think your problem may be that you have value="/Events/Edit/"'+ event.id You probably meant value="/Events/Edit/'+ event.id +'" [the rest of your snippet]

Upvotes: 5

Related Questions