Welcome to WebmasterWorld Guest from 54.205.115.177

Forum Moderators: open

Message Too Old, No Replies

javascripting problem?

cant see whats up

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

10+ Year Member



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)

WebmasterWorld Senior Member 10+ Year Member



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)

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



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)

WebmasterWorld Senior Member 10+ Year Member



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)

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



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