Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Client Side Scripting
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 10-21-2009, 05:19 PM
  #1
jim255
Aspirant (Level 2)
 
Join Date: Oct 2009
Posts: 12
iTrader: (0)
jim255 is an unknown quantity at this point
Getting input from a drop down list

Can anyone tell me what im doing wrong here because this code isnt working for me at the moment

<head>
<title></title>
</head>

<body>
<form action = <"">
<h1>Select color</h1>
<fieldset>
<select id = "selcolor">
<option value = "#FFFFFF">white</option>
<option value = "#FF0000">Red</option>
<option value = "#FFCC00">Orange</option>
</select>

<input type = "button"
value = "change color"
onclick = "changeColor ()" />
</fieldset>
</form>
</body>

</html>

<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/
// from document1.html

function changeColor(){
var selColor = document.getElementById("selColor");
var color = selColor.#FFFFFF;
document.body.style.backgroundColor = color;
} // end function
/*]]>*/
</script>

(this is the javascript, but I am unsure if its right or where I need to insert it)

thanks
jim255 is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-21-2009, 06:25 PM
  #2
Vege
Super Deity (Level 18)
 
Join Date: Sep 2004
Location: Finland
Posts: 3,410
iTrader: (0)
Vege is just really niceVege is just really niceVege is just really niceVege is just really nice
HTML Code:
<html><head>
<title></title>


<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/

function changeColor(){
var selColor = document.getElementById("selcolor");
var color = selColor[selColor.selectedIndex].value;
document.body.style.backgroundColor = color;
} // end function
/*]]>*/
</script>


</head>

<body>
<form action="">
<h1>Select color</h1>
<fieldset>
<select id ="selcolor">

<option value ="#FFFFFF">white</option>
<option value ="#FF0000">Red</option>
<option value ="#FFCC00">Orange</option>
</select>

<input type = "button" value = "change color" onclick = "changeColor ()" />
</fieldset>
</form>
</body>

</html>
It should be something like this.
If i remember correctly IE6 is kinda bad when using style with javascript, better bet is to change stylesheet, not style.

Last edited by Vege : 10-21-2009 at 06:27 PM.
Vege is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-22-2009, 07:13 AM
  #3
jim255
Aspirant (Level 2)
 
Join Date: Oct 2009
Posts: 12
iTrader: (0)
jim255 is an unknown quantity at this point
Thanks Vege that works fine now.

Ive moved on to a different function now but im having the same problem with this one - can you tell me if theres something im doing wrong that is causing me to have these problems?

<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/

function sayHi(){
txtName = document.getElementById("txtName");
divOutput = document.getElementById("divOutput");

name = txtName.value;

divoutput.innerHTML = "<em>" + name + "<\/em>";
divOutput.innerHTML = " is a very nice name. ";
}
/*]]>*/
</script>


<head>
<title></title>
</head>

<body>
<h1>Inner HTML demo</h1>
<form action = "">
<fieldset>
<label>Please type your name</label>
<input type = "text"
id = "txtName" />
<button type = "button"
onclick = "sayHi()">
Click me
</button>
</fieldset>
</form>

<div id = "divOutput">
Watch this space.
</div>
</body>

</html>
jim255 is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-22-2009, 10:45 AM
  #4
Vege
Super Deity (Level 18)
 
Join Date: Sep 2004
Location: Finland
Posts: 3,410
iTrader: (0)
Vege is just really niceVege is just really niceVege is just really niceVege is just really nice
You should be able to check the javascript console for the error thats is created.

Javascript goes inside <head> -tags and you seem to be missing opening <html> -tag.
Vege is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart
 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 10:06 PM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.