javascript - Switch/case usage for selected value in selectbox -


i have selectbox couple of options in it. when option selected, javascript code gets value of selected option , has change font of text accordingly.

i figured use switch-case statement because have multiple options, doesn't seem work, nothing changes.

javascript

function font() {     var sf = document.getelementbyid('box').value;     var generate = document.getelementbyid('generate');      switch (sf) {         case 'timesnewroman':             generate.style.fontfamily('times new roman')             break;         case 'georgia':             generate.style.fontfamily('georgia')             break;         case 'palatinolinotype':             generate.style.fontfamily('palatino linotype')             break;         default:             generate.style.fontfamily('arial')     } } 

html

<select id="box" onchange="font();">     <option id="tnr" value="timesnewroman">times new roman</option>     <option id="grg" value="georgia">georgia</option>     <option id="plt" value="palatinolinotype">palatino linotype</option> </select> <br /> <div id="generate">this text</div> 

note

i have more options in list have shorten sake of simplicity.

am wrong using statement, or missing entirely?

you haven't made assignment, use generate.style.fontfamily = "arial";


Comments

Popular posts from this blog

design - Custom Styling Qt Quick Controls -

Unable to remove the www from url on https using .htaccess -