javascript - Function not defined....My Function Call is not Working -



javascript - Function not defined....My Function Call is not Working -

i need help code. maintain getting error changebg not defined.

the way code should work when select radio button background changes. if alter function inline function within onclick event works if move funtion script section doesn't work example: <input type="radio" id="red" name="change1" value=1 onclick="document.body.style.backgroundcolor='red'" /><label for="red">red</label><br /> works @ changing background red

but when create function in script section , phone call function in onlick event doesn't work,

example of code not working:

script:

<script type="text/javascript"> function changebg(n) { if (n==1) document.body.style.backgroundcolor='red'"; if (n==2) document.body.style.backgroundcolor='yellow'"; if (n==3) document.body.style.backgroundcolor='green'"; if (n==4) document.body.style.backgroundcolor='orange'"; } </script>

html:

<form id="jp2" name="jp2" method="get"> <input type="radio" id="red" name="change1" value=1 onclick="changebg(1)" /> <label for="red">red</label><br /> <input type="radio" id="yellow" name="change1" value=2 onclick="changebg(2)" /> <label for="yellow">yellow</label><br /> <input type="radio" id="green" name="change1" value=3 onclick="changebg(3)" /> <label for="green">green</label><br /> <input type="radio" id="orange" name="change1" value=4 onclick="changebg(4)" /> <label for="orange">orange</label><br /> </form>

backgroundcolor='red'" backgroundcolor='yellow'" backgroundcolor='green'" backgroundcolor='orange'"

you see " quotemarks? rid of them.

your working code

in firefox gives next console error. should larn how simple debugging can grab these errors early.

syntaxerror: unterminated string literal

javascript html

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -