im guessing this would be done with javascript.... what im trying to do is that the body background color of my site changes automaticaly when the user types it into a form (the page doesnt have to refresh)
would that be possible?
| SitePoint Sponsor |


im guessing this would be done with javascript.... what im trying to do is that the body background color of my site changes automaticaly when the user types it into a form (the page doesnt have to refresh)
would that be possible?




It's certainly possible
HTML code:
Javascript code:HTML Code:<form id="colorchanger"> <input type="text" id="color"> <input type="submit" value="Set color"> </form>
Code javascript:window.onload = function (){ var theForm = document.getElementById('colorchanger'); theForm.onsubmit=setColor; } function setColor (){ var colorinput = document.getElementById('color'); var color = colorinput.value; document.getElementsByTagName('body')[0].style.backgroundColor = color; return false; }
This should work, but is still very basic. You probably want to modify the setColor function so it checks to see if the given value is a valid color value, for instance.


thanks bro, ill test it out
edit: what if it had to be just one div instead of body. i tried to edit the getelementbytagName part to just get element by id and typing in the divs id instead of 'body' but it didnt work


no i did not.... ill try that out, thanks
Bookmarks