PDA

View Full Version : Open function in new window.


murphyz
01-05-2003, 11:27 PM
I have a 'function generate()' script on a page which takes a set amount of html, adds specific text that a user fills in on a form and displays all of this together as html within a text area so that the user can fill out a form, generate the code, copy and paste the information to their site.

That part works fine, but I would like to have a preview button so that the result can be displayed in a new window to ensure it is correct prior to generating the code - is this possible?

An example of what is set up is as follows:

<script>
function generate() {
var code = "welcome to my page - please fill out the form below and copy and paste the code to your site."+document.f.title.value+"<img src=\""+document.f.img.value+"\"> "+document.f.date.value;
code += "<br>"+document.f.name.value+"<br>"+document.f.sub1.value+"<br>"+document.f.sub2.value;
document.f.c.value=code;
}
</script>

<form name="f">
Title - <input type="text" name="title"><br>
Image - <input type="text" name="img"><br>
Name - <input type="text" name="name"><br>
Date - <input type="text" name="date"><br>
Subtext 1 - <input type="text" name="sub1" maxlength="48"><br>
Subtext 2 - <input type="text" name="sub2" maxlength="86"><br>
<input type="button" value="Generate Code!" onclick="generate()"><br><br>
<textarea name="c" rows="8" cols="40">Your generated code will appear here.</textarea>
</form>

I would like an additional button that previews the result in a new window.

Thanks for your help

Mxx

chrismiceli
01-06-2003, 01:03 AM
try this
[cde]
<script>
function prevgenerate() {
function generate() {
var code = "welcome to my page - please fill out the form below and copy and paste the code to your site."+document.f.title.value+"<img src=\""+document.f.img.value+"\"> "+document.f.date.value;
code += "<br>"+document.f.name.value+"<br>"+document.f.sub1.value+"<br>"+document.f.sub2.value;
var win = document.open("","prev",width=400,height=338,toolbar,");
win.document.writeln(code);
}
</script>
[/code]

murphyz
01-06-2003, 03:05 PM
Thanks for the reply. unfortunately I'm still having no luck.

I tried playing around with the script above, and also with innerHTML to try and change the image I want but am still having no luck at all.

The page I am needing the preview for is here:
http://www.cowandchicken.plus.com/murphyz/milkmissing.htm

Any further help in getting the preview to work either on the same page or in a new window would be greatly appreciated.

Thanks

Mxx