mysqlfrk
Programmer
- Aug 3, 2011
- 12
Hi,
I want to create an input element and a button,and ask user to give a color name in the input box,and after clicking the button the color of the div will change.
Now here is my code . I tried this code but it doesnot work-
<html>
<head>
<script type='text/javascript'>
function fun() {
var cr=document.getElementById('nm').value;
var element = parsedocument.getElementById("example");
element.style.backgroundColor=cr;
}
</script>
</head>
<body>
<div id="example" onClick="fun()">
<br><br><center><b>Click the Submit button to change the color of this div
as per input</b></center></div>
<br> <br>
Enter Color: <input type="text" id="nm"><br><br><br>
<input type="submit" value="Submit">
</body>
</html>
What can be wrong with the above code?
Hope you can help me.
Thanks in advance.
I want to create an input element and a button,and ask user to give a color name in the input box,and after clicking the button the color of the div will change.
Now here is my code . I tried this code but it doesnot work-
<html>
<head>
<script type='text/javascript'>
function fun() {
var cr=document.getElementById('nm').value;
var element = parsedocument.getElementById("example");
element.style.backgroundColor=cr;
}
</script>
</head>
<body>
<div id="example" onClick="fun()">
<br><br><center><b>Click the Submit button to change the color of this div
as per input</b></center></div>
<br> <br>
Enter Color: <input type="text" id="nm"><br><br><br>
<input type="submit" value="Submit">
</body>
</html>
What can be wrong with the above code?
Hope you can help me.
Thanks in advance.