homepage Welcome to WebmasterWorld Guest from 54.145.209.80
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
javascripting problem?
cant see whats up
antipodes

10+ Year Member



 
Msg#: 293 posted 7:33 am on Mar 3, 2003 (gmt 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>

 

hakre

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 293 posted 8:02 am on Mar 3, 2003 (gmt 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.

txbakers

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



 
Msg#: 293 posted 2:06 pm on Mar 3, 2003 (gmt 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.

hakre

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 293 posted 3:44 pm on Mar 3, 2003 (gmt 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... ;)

txbakers

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



 
Msg#: 293 posted 4:12 pm on Mar 3, 2003 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved