kramden88
kramden88

Reputation: 25389

jQuery Need Help Escaping Variables

I'm trying to combine these variables and append them to a select tag but the vars contain special characters and everything gets all jumbled up. No matter how I try to escape the special characters I can't get it to work. Can anyone take a look and tell me what I'm doing wrong?

var contractid = $(this).attr("ows_ID");
var hrefa = "javascript\:SelectField\(\'\{808AEFE9-F68B-4F7B-AF62-C5B32723BBC1\}\'\,\'";
var hrefb = "'\)\;return\ false\;";

var optionline = "<option value='"+hrefa+""+contractid+""+hrefb+"'>otherstuff</option>";

The final product is supposed to look like this:

javascript:SelectField('{808AEFE9-F68B-4F7B-AF62-C5B32723BBC1}','133');return false;

but it always comes out like this:

false;'="" {808aefe9-f68b-4f7b-af62-c5b32723bbc1}','115');return="" value="javascript:SelectField("

Upvotes: 1

Views: 603

Answers (2)

OptimusCrime
OptimusCrime

Reputation: 14863

I've played around on jsfiddle now.

This looks correct to me?

http://jsfiddle.net/Y7BP7/3/

Upvotes: 1

kojiro
kojiro

Reputation: 77107

You're making it more complex than it needs to be. Just reverse the quotes in the output.

var contractid = $(this).attr("ows_ID"),
    hrefa = "javascript:SelectField('{808AEFE9-F68B-4F7B-AF62-C5B32723BBC1}','",
    hrefb = "');return false;",
    optionline = '<option value="' + hrefa + contractid + hrefb + '">otherstuff</option>';

Upvotes: 1

Related Questions