Welcome to WebmasterWorld Guest from 23.22.140.143

Forum Moderators: open

Message Too Old, No Replies

javascripting problem?

cant see whats up

     
7:33 am on Mar 3, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 30, 2002
posts:71
votes: 0


New to JS and can't see what error Ive made here/why it isn't working. Note, i originally used eval in the onclick function but someone told me i didn't need it. Didn't work with that either.........

<html>
<head>
<title>Objects, methods and events.</title>

</head>

<body bgcolor="red">

<script language="JavaScript">
<!-- hide
var user=prompt("Hello! What is your name?");
var outputString="Nice to meet you "+user+"! Welcome to my page";
alert(outputString);

var silvervar="silver"
var whitevar="white"
var resetvar="#cccc99"
//close hide -->

document.write("<form><input type='button' value='Silver' onClick='document.bgColor='silvervar'></form>");
document.write("<form><input type='button' value='White' onClick='document.bgColor='whitevar'></form>");
document.write("<form><input type='button' value='reset' onClick='document.bgColor='resetvar'></form>");

</script>


</body>
</html>

8:02 am on Mar 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 7, 2003
posts:1230
votes: 0


hi antipodes,

you mixed some 'ses:

document.write("<form><input type='button' value='Silver' onClick='document.bgColor='silvervar'></form>");
...

use this instead:

document.write("<form><input type='button' value='Silver' onClick='document.bgColor='"+silvervar+"'></form>");
...

you need to insert the vars into the string. this won't work autmatically. so a + is used to connect strings.

tip: having problems in such cases use netscape and viewsource to see the javascript generated sourcecode.

2:06 pm on Mar 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Sept 1, 2001
posts:4392
votes: 0


You win't see anything in Netscape either because you are using form elements (input) without a form tag.

IE will allow this, but Netscape won't.

Put in some form tags and you'll be closer.

3:44 pm on Mar 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 7, 2003
posts:1230
votes: 0


Put in some form tags and you'll be closer.

form tags are placed. see the code.

the choice for netscape was about the viewsource command. this will display not the source of the page like retrieved, it will display the source of the page after javascript changed the document content with these changes. so it count nothing if a form tag would have been obmitted.

txbakers, i think you've mixed it up a bit... ;)

4:12 pm on Mar 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Sept 1, 2001
posts:4392
votes: 0


ah yes I see, sorry about that. too sleepy. too much coding. must rest.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members