Jump to content

document.write('What?')


george

Recommended Posts

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

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

Try this insteadmyWindow.write("<input type='button' onClick='saveclass(true)' value='Save'>");

Link to comment
Share on other sites

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...