By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,506 Members | 1,876 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,506 IT Pros & Developers. It's quick & easy.

Sorry: its my first script. what is wrong?

P: n/a
Please can you find out what's wrong, fix the script and tell me what was
wrong. Im just beginning
<html>
<head>
<title>Random Mad Lib!</title>
<script language="JavaScript">
<!-- Hide

function displaymadlib(w1, w2, w3, w4, w5, w6, w7, w8, w9, w0, w11, w22, w33,
w44, w55) {

document.writeln("The attack of the purple tissue!!!<br> Once there was
a/an "
+ w1
+ " tissue attacking a "
+ w2
+ " in"
+ w3
+ "! The tissue was even"
+ w4
+ "the"
+ w5
+ "! 4"
+ w6
+ "died of heart attacks. The"
+ w7
+ "was"
+ w8
+ "Suddenly, "
+ 9
+ "man came to"
+ w0
+ "the"
+ w11
+ ". He went up to the tissue and kicked it in the
+ w22
+ ", and the tissue"
+ w33
+ "to the ground. Its snot covered the "
+ w44
+ ", and everything there"
+ w55
+ ".");return true
}

// stop hiding -->

</SCRIPT>

</head>

<body onload="document.madlib.adj1.select()">

<FORM NAME="madlib">
<p>
adjective:
<input name="adj1"></p><br>
<p>
place:
<input name="place1"></p><br>
<p>
another place:
<input name="place2"></p><br>
<p>
verb:
<input name="verb1"></p><br>
<p>
plural noun:
<input name="pnoun1"></p><br>
<p>
another plural noun:
<input name="pnoun2"></p><br>
<p>
place:
<input name="place3"></p><br>
<p>
adjective:
<input name="adj2"></p><br>
<p>
noun:
<input name="noun1"></p><br>
<p>
verb:
<input name="verb2"></p><br>
<p>
noun:
<input name="noun2"></p><br>
<p>
body part:
<input name="bpart"></p><br>
<p>
verb:
<input name="verb3"></p><br>
<p>
place:
<input name="place4"></p><br>
<p>
verb:
<input name="verb4"></p><br>
<p>
<br>
<p>

<INPUT TYPE="button" NAME="Submit" VALUE="Submit to get your mad lib!"
OnClick="displaymadlib(document.madlib.adj1.value,
document.madlib.place1.value, document.madlib.place2.value,
document.madlib.verb1.value, document.madlib.pnoun1.value,
document.madlib.pnoun2.value, document.madlib.place3.value,
document.madlib.adj2.value, document.madlib.noun1.value,
document.madlib.verb2.value, document.madlib.noun2.value,
document.madlib.bpart.value, document.madlib.verb3.value,
document.madlib.place4.value, document.madlib.verb4.value)">

<INPUT TYPE="reset" VALUE="reset">

</form>
</body>

</html>
Jul 23 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
You just gotta check every line, coz its small mistakes like not closing a
line with " etc...
======================
<html>
<head>
<title>Random Mad Lib!</title>
<script language="JavaScript">
<!-- Hide

function displaymadlib() {
w1 = document.madlib.adj1.value
w2 = document.madlib.place1.value,
w3 = document.madlib.place2.value
w4 = document.madlib.verb1.value
w5 = document.madlib.pnoun1.value
w6 = document.madlib.pnoun2.value
w7 = document.madlib.place3.value
w8 = document.madlib.adj2.value
w9 = document.madlib.noun1.value
w10 = document.madlib.verb2.value
w11 = document.madlib.noun2.value
w12 = document.madlib.bpart.value
w13 = document.madlib.verb3.value
w14 = document.madlib.place4.value
w15 = document.madlib.verb4.value

document.writeln("The attack of the purple tissue!!!<br> Once there was
a/an "
+ w1
+ " tissue attacking a "
+ w2
+ " in "
+ w3
+ "! The tissue was even "
+ w4
+ "the "
+ w5
+ "! 4 "
+ w6
+ "died of heart attacks. The "
+ w7
+ "was"
+ w8
+ "Suddenly, "
+ w9
+ "man came to"
+ w10
+ "the "
+ w11
+ ". He went up to the tissue and kicked it in the "
+ w12
+ ", and the tissue"
+ w13
+ "to the ground. Its snot covered the "
+ w14
+ ", and everything there "
+ w15
+ ".");return true
}

// stop hiding -->

</SCRIPT>

</head>

<body onload="document.madlib.adj1.select()">

<FORM NAME="madlib">
<p>
adjective:
<input name="adj1"></p><br>
<p>
place:
<input name="place1"></p><br>
<p>
another place:
<input name="place2"></p><br>
<p>
verb:
<input name="verb1"></p><br>
<p>
plural noun:
<input name="pnoun1"></p><br>
<p>
another plural noun:
<input name="pnoun2"></p><br>
<p>
place:
<input name="place3"></p><br>
<p>
adjective:
<input name="adj2"></p><br>
<p>
noun:
<input name="noun1"></p><br>
<p>
verb:
<input name="verb2"></p><br>
<p>
noun:
<input name="noun2"></p><br>
<p>
body part:
<input name="bpart"></p><br>
<p>
verb:
<input name="verb3"></p><br>
<p>
place:
<input name="place4"></p><br>
<p>
verb:
<input name="verb4"></p><br>
<p>
<br>
<p>

<INPUT TYPE="button" NAME="Submit" VALUE="Submit to get your mad lib!"
OnClick="displaymadlib()">

<INPUT TYPE="reset" VALUE="reset">

</form>
</body>

</html>
========================
"Rtritell" <rt******@aol.com> wrote in message
news:20***************************@mb-m14.aol.com...
Please can you find out what's wrong, fix the script and tell me what was
wrong. Im just beginning
<html>
<head>
<title>Random Mad Lib!</title>
<script language="JavaScript">
<!-- Hide

function displaymadlib(w1, w2, w3, w4, w5, w6, w7, w8, w9, w0, w11, w22, w33, w44, w55) {

document.writeln("The attack of the purple tissue!!!<br> Once there was a/an "
+ w1
+ " tissue attacking a "
+ w2
+ " in"
+ w3
+ "! The tissue was even"
+ w4
+ "the"
+ w5
+ "! 4"
+ w6
+ "died of heart attacks. The"
+ w7
+ "was"
+ w8
+ "Suddenly, "
+ 9
+ "man came to"
+ w0
+ "the"
+ w11
+ ". He went up to the tissue and kicked it in the
+ w22
+ ", and the tissue"
+ w33
+ "to the ground. Its snot covered the "
+ w44
+ ", and everything there"
+ w55
+ ".");return true
}

// stop hiding -->

</SCRIPT>

</head>

<body onload="document.madlib.adj1.select()">

<FORM NAME="madlib">
<p>
adjective:
<input name="adj1"></p><br>
<p>
place:
<input name="place1"></p><br>
<p>
another place:
<input name="place2"></p><br>
<p>
verb:
<input name="verb1"></p><br>
<p>
plural noun:
<input name="pnoun1"></p><br>
<p>
another plural noun:
<input name="pnoun2"></p><br>
<p>
place:
<input name="place3"></p><br>
<p>
adjective:
<input name="adj2"></p><br>
<p>
noun:
<input name="noun1"></p><br>
<p>
verb:
<input name="verb2"></p><br>
<p>
noun:
<input name="noun2"></p><br>
<p>
body part:
<input name="bpart"></p><br>
<p>
verb:
<input name="verb3"></p><br>
<p>
place:
<input name="place4"></p><br>
<p>
verb:
<input name="verb4"></p><br>
<p>
<br>
<p>

<INPUT TYPE="button" NAME="Submit" VALUE="Submit to get your mad lib!"
OnClick="displaymadlib(document.madlib.adj1.value,
document.madlib.place1.value, document.madlib.place2.value,
document.madlib.verb1.value, document.madlib.pnoun1.value,
document.madlib.pnoun2.value, document.madlib.place3.value,
document.madlib.adj2.value, document.madlib.noun1.value,
document.madlib.verb2.value, document.madlib.noun2.value,
document.madlib.bpart.value, document.madlib.verb3.value,
document.madlib.place4.value, document.madlib.verb4.value)">

<INPUT TYPE="reset" VALUE="reset">

</form>
</body>

</html>

Jul 23 '05 #2

P: n/a
On Fri, 7 May 2004 00:14:29 +0200, Dominique <ni****@webadstudio.com>
wrote:

Valid HTML documents should have a document type declaration:

<URL:http://www.w3.org/TR/html4/struct/global.html#h-7.2>
<html>
<head>
<title>Random Mad Lib!</title>
<script language="JavaScript">
This should read

<script type="text/javascript">

The type attribute is required, whereas the language attribute is
deprecated and should no longer be used.
<!-- Hide
The practice of script hiding is now obsolete. Remove the SGML comment
delimiters.
function displaymadlib() {
w1 = document.madlib.adj1.value
w2 = document.madlib.place1.value,
w3 = document.madlib.place2.value
w4 = document.madlib.verb1.value
w5 = document.madlib.pnoun1.value
w6 = document.madlib.pnoun2.value
w7 = document.madlib.place3.value
w8 = document.madlib.adj2.value
w9 = document.madlib.noun1.value
w10 = document.madlib.verb2.value
w11 = document.madlib.noun2.value
w12 = document.madlib.bpart.value
w13 = document.madlib.verb3.value
w14 = document.madlib.place4.value
w15 = document.madlib.verb4.value
Why did you decide to create a series of global variables? Use the var
keyword to keep them local.

By the way, this would be better written as:

function displayMadLib( form ) {
var elems = form.elements;

// Could use an array rather than separate variables
var w1 = elems[ 'adj1' ].value,
w2 = elems[ 'place1' ].value,
w3 = elems[ 'place2' ].value,
w4 = elems[ 'verb1' ].value,
w5 = elems[ 'pnoun1' ].value,
w6 = elems[ 'pnoun2' ].value,
w7 = elems[ 'place3' ].value,
w8 = elems[ 'adj2' ].value,
w9 = elems[ 'noun1' ].value,
w10 = elems[ 'verb2' ].value,
w11 = elems[ 'noun2' ].value,
w12 = elems[ 'bpart' ].value,
w13 = elems[ 'verb3' ].value,
w14 = elems[ 'place4' ].value,
w15 = elems[ 'verb4' ].value;

[snip]
// stop hiding -->
Remove this.

[snip]
<INPUT TYPE="button" NAME="Submit" VALUE="Submit to get your mad lib!"
OnClick="displaymadlib()">


This would need to be changed to:

... onclick="displayMadLib(this.form)">

[snipped top-post]

Mike
Please don't top post.

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #3

P: n/a
lol@mike

ok... didn't know i was sposed to nail the guy on it... lol*
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:op**************@news-text.blueyonder.co.uk...
On Fri, 7 May 2004 00:14:29 +0200, Dominique <ni****@webadstudio.com>
wrote:

Valid HTML documents should have a document type declaration:

<URL:http://www.w3.org/TR/html4/struct/global.html#h-7.2>
<html>
<head>
<title>Random Mad Lib!</title>
<script language="JavaScript">


This should read

<script type="text/javascript">

The type attribute is required, whereas the language attribute is
deprecated and should no longer be used.
<!-- Hide


The practice of script hiding is now obsolete. Remove the SGML comment
delimiters.
function displaymadlib() {
w1 = document.madlib.adj1.value
w2 = document.madlib.place1.value,
w3 = document.madlib.place2.value
w4 = document.madlib.verb1.value
w5 = document.madlib.pnoun1.value
w6 = document.madlib.pnoun2.value
w7 = document.madlib.place3.value
w8 = document.madlib.adj2.value
w9 = document.madlib.noun1.value
w10 = document.madlib.verb2.value
w11 = document.madlib.noun2.value
w12 = document.madlib.bpart.value
w13 = document.madlib.verb3.value
w14 = document.madlib.place4.value
w15 = document.madlib.verb4.value


Why did you decide to create a series of global variables? Use the var
keyword to keep them local.

By the way, this would be better written as:

function displayMadLib( form ) {
var elems = form.elements;

// Could use an array rather than separate variables
var w1 = elems[ 'adj1' ].value,
w2 = elems[ 'place1' ].value,
w3 = elems[ 'place2' ].value,
w4 = elems[ 'verb1' ].value,
w5 = elems[ 'pnoun1' ].value,
w6 = elems[ 'pnoun2' ].value,
w7 = elems[ 'place3' ].value,
w8 = elems[ 'adj2' ].value,
w9 = elems[ 'noun1' ].value,
w10 = elems[ 'verb2' ].value,
w11 = elems[ 'noun2' ].value,
w12 = elems[ 'bpart' ].value,
w13 = elems[ 'verb3' ].value,
w14 = elems[ 'place4' ].value,
w15 = elems[ 'verb4' ].value;

[snip]
// stop hiding -->


Remove this.

[snip]
<INPUT TYPE="button" NAME="Submit" VALUE="Submit to get your mad lib!"
OnClick="displaymadlib()">


This would need to be changed to:

... onclick="displayMadLib(this.form)">

[snipped top-post]

Mike
Please don't top post.

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)

Jul 23 '05 #4

P: n/a
Ron
Heya rt,
I'm going at add a little to Mike's reply in the interest of caution
when using document.write and document.writeln. It is
encouraged to use document.open() to let the browser know you're going
to be creating a new document and document.close()
to tell the browser exactly when it can render the new document. My
browser in particular (Mozilla 1.7b) never "finished" loading the page.
Also, it's important to be aware that document.write() writes the entire
document.
In other words, you've left out "<html><head>..." etc. and you just have
a document consisting of "The attack of the purple tissue!...". While many
browsers will default to wrapping and rendering such a document fragment
as HTML, it's good practice to give your new document a definite
document type
node and a definite core structure:

var docHeader = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
// Mike likes HTML4.01, but I prefer introducing the simplicity of XML for new web designers.
docHeader += "<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD XHTML 1.1\/\/EN\" \"http:\/\/www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n";
// Double slashes have to be escaped lest they be mistaken for comments.
docHeader += "<html xmlns=\"http:\/\/www.w3.org/1999/xhtml\" xml:lang=\"en\">";
docHeader += "<head>\n";
docHeader += "<meta http-equiv=\"Content-Type\" content=\"application/xhtml+xml; charset=iso-8859-1\">\n";
docHeader += "<title>Random Mad Lib - Your Mad Lib!</title>\n";
docHeader += "</head>\n";
docHeader += "<body>\n";
var docFooter = "</body>\n</html>";
// The above two variables are good to keep around if you use document.write/ln a lot.

[snip]

document.open();
document.write(docHeader);
document.writeln("The attack of the purple tissue!!!<br> Once there was a/an "
+ w1
+ " tissue attacking a "
+ w2
+ " in"
+ w3
+ "! The tissue was even"
+ w4
+ "the"
+ w5
+ "! 4"
+ w6
+ "died of heart attacks. The"
+ w7
+ "was"
+ w8
+ "Suddenly, "
+ w9
+ "man came to"
+ w10
+ "the"
+ w11
+ ". He went up to the tissue and kicked it in the"
+ w12
+ ", and the tissue"
+ w13
+ "to the ground. Its snot covered the "
+ w14
+ ", and everything there"
+ w15
+ ".");
document.write(docFooter);
document.close();
Jul 23 '05 #5

P: n/a
Ron wrote:
<snip>
var docHeader = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
// Mike likes HTML4.01, but I prefer introducing the simplicity of
XML for new web designers.

<snip>

That is a strange notion in the context of a post discussing the -
write - method as Mozilla's XHTML DOM does not implement the W3C HTML
DOM HTMLDocument interface on the document object, and as a result does
not implement a - write - method at all. So introducing the new web
designer to XHTML in this context implies abandoning the whole approach
in favour of the namespace versions of the DOM Core Node manipulation
methods, for the replacement of the content.

While I don't agree with the decision not to implement HTMLDocument in
the XHTML DOM on Mozilla, Mozilla is easily the most widely used browser
that provides a scriptable DOM for use with XHTML so its implementation
is significant when considering the subject of scripting XHTML
documents.

Richard.
Jul 23 '05 #6

P: n/a
Ron
Richard Cornford wrote:
[snip]
That is a strange notion in the context of a post discussing the -
write - method as Mozilla's XHTML DOM does not implement the W3C HTML
DOM HTMLDocument interface on the document object, and as a result does
not implement a - write - method at all. So introducing the new web
designer to XHTML in this context implies abandoning the whole approach
in favour of the namespace versions of the DOM Core Node manipulation
methods, for the replacement of the content.

While I don't agree with the decision not to implement HTMLDocument in
the XHTML DOM on Mozilla, Mozilla is easily the most widely used browser
that provides a scriptable DOM for use with XHTML so its implementation
is significant when considering the subject of scripting XHTML
documents.

Richard.

Heya Richard,
Interesting, I never noticed that (I've managed to avoid using
document.write() in any of my projects).
Although it's still listed under the DOM Inspector, I noticed that
trying to use it just returns an internal context error. Many other
DOM2 HTML interfaces are still implemented, though. Where can I see a
specification of Mozilla's XHTML DOM ?
Jul 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.