drop down menu call javascript function

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Oct 2007
Posts: 67
Reputation: still_learning is an unknown quantity at this point 
Solved Threads: 0
still_learning still_learning is offline Offline
Junior Poster in Training

drop down menu call javascript function

 
0
  #1
May 28th, 2008
Hey guys,

I am trying to make a drop down menu that gives options such as (right, left, center) so that I can choose one of those and align the text in one of my layers. I am having trouble figuring out how to make this work so if someone can help me that would be great.

Basically I need a drop down menu with those three options, and when one of the options is chosen, I need it to call a javascript function onchange (i don't want to use a button, i just want to align the text instantly) and then I need the javascript function to use getElementById('mylayer') to change the alignment of the text in that layer. Can anyone help me? I'm sure it is simple and involves the values of my drop down menu, but I cannot manage to figure it out. Thanks!
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 1
Reputation: Nandish is an unknown quantity at this point 
Solved Threads: 1
Nandish Nandish is offline Offline
Newbie Poster

Re: drop down menu call javascript function

 
0
  #2
May 29th, 2008
Originally Posted by still_learning View Post
Hey guys,

I am trying to make a drop down menu that gives options such as (right, left, center) so that I can choose one of those and align the text in one of my layers. I am having trouble figuring out how to make this work so if someone can help me that would be great.

Basically I need a drop down menu with those three options, and when one of the options is chosen, I need it to call a javascript function onchange (i don't want to use a button, i just want to align the text instantly) and then I need the javascript function to use getElementById('mylayer') to change the alignment of the text in that layer. Can anyone help me? I'm sure it is simple and involves the values of my drop down menu, but I cannot manage to figure it out. Thanks!
try this.........

  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4.  
  5. function alignl(ele){
  6. document.getElementById('lay').style.align=ele;
  7. }
  8. </script>
  9. </head>
  10. <body>
  11. <layer id='lay'></layer>
  12. <select id='s' name='s' onchange="alignl(this.value);">
  13. <option value="left">left</option>
  14. <option value="right">right</option>
  15. <option value="center">center</option>
  16. <option value="top">top</option>
  17. </select>
  18. </body>
  19. </html>
Last edited by peter_budo; May 31st, 2008 at 7:27 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 67
Reputation: still_learning is an unknown quantity at this point 
Solved Threads: 0
still_learning still_learning is offline Offline
Junior Poster in Training

Re: drop down menu call javascript function

 
0
  #3
May 29th, 2008
Thanks for the solution. I had already solved it myself, but since you posted the same exact solution that I came up with myself I will go ahead and add to your reputation.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC