views:

30

answers:

1

Hi all,

I'm kinda stuck.

I defined three variables:

var part1 = "<form><input type='button' value='Open Window' onclick='window.open('http://jsfiddle.net/
";
var part2="5Xket,"
var part3 = "'toolbar=no',menubar='no')></form>";

My aim is to concat those variables to create a working link when clicking on the button.

This is my try to concat the values of the variables.

var mytest_2=part1+part2+part3;
alert (mytest_2);

By clicking a button the button from mytest2 should appear. Clicking on that button there should be opened a new window with the url http://jsfiddle.net/5Xket/

$('#searchbutton').click(function() {
$("<td class='testclass'><input id='an_id' type='text'></td>").show();
$(mytest_2).insertAfter('#an_id');

Well, the button appears as it should, but won't open a window. My guess is that I'm wrong with the syntax somewhere because the alert puts out the correct order of variables.

Any ideas? Thank you.

+1  A: 

I should do this way:

var part1 = '<form><input id="button1" type="button" value="Open Window" /></form>';

$(part1).insertAfter('#an_id');

$('#button1').click(function(){
   window.open('http://jsfiddle.net/','5Xket','toolbar=no,menubar=no');
});

The problem with your code is double/single quotes aren't properly escaped.

jerjer
Hm, that is what I'm looking for : window.open('http://jsfiddle.net/5Xket','toolbar=no,menubar=no'); I want to concat the regular adress with a special fiddle named 5Xket.
Stumphy