Click to See Complete Forum and Search --> : My javascript Generator wont work


neil9999
07-06-2003, 02:45 PM
Hi,

I'm currently in the process of making a javascript generator which will produce a variety of scripts. I'm having trouble with the bit that generates an alert which appears when you close the page. I know the code to do this, I just can't generate it. This is the code for the whole page at the moment:

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
<script LANGUAGE="JavaScript">

function jumpBox(list) {
location.href = list.options[list.selectedIndex].value
}

//created by Neil Poole

function compute(form) {

form.html.value = ("<body onUnload='alert("' + form.alert.value + '")"'>");

}

{
}

{

}

</script>

</head>

<body bgcolor="#C0C0C0">
<p align="center">Alert which appears when you close the page.</p>
<form>
<p align="left">Enter text to be displayed on the alert:&nbsp;</p>
<p align="left"> <input type="text" name="alert" size="55" value="Thanks for visiting this page. Please come again soon!"></p>
<p align="left"><input TYPE="button" VALUE="Generate"
ONCLICK="compute(this.form)"><input type="reset" value="Reset" name="Erase">
</p>
<p align="left">Paste this code where you want the close button to go:
</p>
<p align="left"><textarea rows="4" name="html" cols="60"></textarea>
</p>
</form>

<p><input type="button" value="Close" name="B3" onClick="javascript:window.close();"><input type="button" value="< Back" name="B4" onclick='window.location="javascriptgenerator3alert.htm";'><input type="button" value="Next >" name="B5" onclick='window.location="javascriptgenerator2.htm";'><input type="button" value="Finish" name="B6" onclick="alert('Complete the wizard before clicking Finish')"></p>
</body>
</html>



Users enter the text they want on the alert into a text box named 'alert' and the generated code appears in a text area named 'html'. Does anyone know what i'm doing wrong?

(the back and forward buttons work, the files they link to are on my hard-drive.)

Thanks,

Neil:confused:

David Harrison
07-06-2003, 03:10 PM
Try using this:

form.html.value = "<body onunload='alert(\""+form.alert.value+"\");'>";

It just looks like you got a bit muddle'd about quotation marks.
If the above code looks a bit confusing at first, don't worry because as long as you remember to treat \" as a single unit you'll be OK.

generally if you have some script with quotation marks inside quotation marks inside quotation marks etc. the order is like this:

" ' \" \' etc. but remember to close them properly.

you could just as easily use

' " \' \" etc.

neil9999
07-07-2003, 03:13 PM
Thanks alot. It works perfectly now

David Harrison
07-07-2003, 03:45 PM
You're welcome.