image - Javascript background changer no working -
i want implement background image changer in code, doesn't seem work.
here js:
function xax() { var p = document.getelementbyid("background1"); var o = document.getelementbyid("background2"); var = document.getelementbyid("background3"); if {p.checked === true} { document.body.style.backgroundimage = "url(gates.jpg)"; } else if {o.checked === true} { document.body.style.backgroundimage = "url(city.jpg)"; } else if {i.checked === true} { document.body.style.backgroundimage = "url(forest.jpg)"; } }
here html:
<input type="radio" id="background1" name="background" >gates of argonath</input><br> <input type="radio" id="background2" name="background" >minas tirith</input><br> <input type="radio" id="background3" name="background" >rivendell</input><br> <input type="button" value="submit" onclick="xax()">
please find correct code below
<html> <body> <input type="radio" id="background1" name="background" >gates of argonath</input><br> <input type="radio" id="background2" name="background" >minas tirith</input><br> <input type="radio" id="background3" name="background" >rivendell</input><br> <input type="button" value="submit" onclick="xax()"> <body> <script> function xax() { var p = document.getelementbyid("background1"); var o = document.getelementbyid("background2"); var = document.getelementbyid("background3"); if (p.checked == true) { document.body.style.backgroundimage = "url(gates.jpg)"; } else if (o.checked == true) { document.body.style.backgroundimage = "url(city.jpg)"; } else if (i.checked == true) { document.body.style.backgroundimage = "url(forest.jpg)"; } } </script> </html>
you using {
after if , else if statement, should use (
Comments
Post a Comment