george Posted June 5, 2008 Share Posted June 5, 2008 I am trying to get the following to work: myWindow.document.write('<button onclick="saveclass('+true+');">Save</button> I have a function, saveclass, that wants to know if I am passing "true" or "flase" to it. I am using the wrong approach here. I tried assigning true or false to a variable. But how can I pass a variable or a literal to a function that is written using document.write? Link to comment Share on other sites More sharing options...
Ingolme Posted June 5, 2008 Share Posted June 5, 2008 Don't use document.write()Use the innerHTML of an element or access a node with DOM.document.write() is one of the worst ways of writing anything with Javascript. It completely clears the page when used after the page has loaded. Link to comment Share on other sites More sharing options...
vytas Posted June 5, 2008 Share Posted June 5, 2008 Try this insteadmyWindow.write("<input type='button' onClick='saveclass(true)' value='Save'>"); Link to comment Share on other sites More sharing options...
Ingolme Posted June 5, 2008 Share Posted June 5, 2008 Actually, if the new window has nothing in it then document.write() will work.Your problem is that you forgot to close the quotes and parenthesis.Another thing: if this window was just created, calling a javascript function that doesn't exist in it won't work. You'll need to call javascript from the other window using window.openerTry this:myWindow.document.write('<button onclick="window.opener.saveclass(true);">Save</button>');And if "true" was supposed to be a variable name, it's a reserved word. You'll have to use another name. Link to comment Share on other sites More sharing options...
george Posted June 5, 2008 Author Share Posted June 5, 2008 Still did not pass the value. But it did not generate an error either - until it tried to pass a parameter, true or false. I have a close button, which merely closes the window. It works just fine. myWindow.document.write('<button onclick="window.close();">Cancel</button>'); But here, the on click event is not calling a function which passes parameters. I need to know how I can pass parameters, or a literal, from within the write function. It does not seem to want to. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 5, 2008 Share Posted June 5, 2008 myWindow.document.write('<button onclick="saveclass(true);">Save</button>'); Link to comment Share on other sites More sharing options...
george Posted June 5, 2008 Author Share Posted June 5, 2008 myWindow.document.write('<button onclick="window.opener.saveclass(true);">Save</button>');That did it. Thanks!! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.