Jump to content

change onclick buttons to onchange from a select


tryingtolearn

Recommended Posts

I am trying to be able to change the font-size and font of text in  a div

 

 

Right now I am using individual buttons for each like this (This works but...)

 

<script type="text/javascript"> 
  function fs(n)  { 
    document.getElementById('C').style.fontSize = n 
  } 
  function fn(n)  { 
    document.getElementById('C').style.fontFamily = n 
  } 
  
  </script> 
  <div style="font-family: arial, helvetica, sans-serif; color: #336699;" id="C">Text</div> 
  
  <input type="button" onClick="fs('12px')" value="12px"> 
  <input type="button" onClick="fs('14px')" value="14px"> 
  <input type="button" onClick="fs('18px')" value="18px"> 
  <input type="button" onClick="fs('24px')" value="24px"> 
  <input type="button" onClick="fs('36px')" value="36px"> 
  <input type="button" onClick="fs('48px')" value="48px"> 
  <input type="button" onClick="fs('60px')" value="60px"> 
  <input type="button" onClick="fs('72px')" value="72px">
  
  <input type="button" onClick="fn('arial')" value="arial"> 
  <input type="button" onClick="fn('tahoma')" value="tahoma"> 
  <input type="button" onClick="fn('times new roman')" value="times new roman"> 
  

 

But Id rather use two dropdown boxes like

 

<select name="fontSize"">

<option value="12px">12px</option>
<option value="14px">14px</option>
<option value="22px">22px</option>
<option value="36px">36px</option>
<option value="72px">72px</option>
</select>

<select name="font"">

<option value="arial">arial</option>
<option value="tahoma">tahoma</option>

</select>

 

But I cant seem to figure that out

 

Any ideas on the direction I need to be going in?

 

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.