yosii Posted December 16, 2012 Share Posted December 16, 2012 <html> <head> </head> <body> <script type="text/javascript"> function change(num) { document.getElementById('tex').innerHTML= 'SSS'+num; } </script> <select name="godel"> <option value="NUM1" onclick ="change('a');">aa</option> <option value="NUM2" onclick ="change('b');">bb</option> <option value="NUM3" onclick ="change('c');">cc</option> </select> <br/> <div id='tex'> </div> </body> </html> I WANT TO CHANGE the value of div in firefox it is work in chrome no why please??? Quote Link to comment Share on other sites More sharing options...
kimi2k Posted December 16, 2012 Share Posted December 16, 2012 Try this: <html> <head> </head> <body> <script type="text/javascript"> function getSelectedText(elementId) { var elt = document.getElementById(elementId); if (elt.selectedIndex == -1) return null; return elt.options[elt.selectedIndex].text; } function change(num) { var text = getSelectedText('sel') document.getElementById('tex').innerHTML= 'SSS'+text[1]; } </script> <select name="godel" onchange ="change('a');" id="sel"> <option value="NUM1" >aa</option> <option value="NUM2" >bb</option> <option value="NUM3" >cc</option> </select> <br/> <div id='tex'> </div> </body> </html> tested in Chromium 22.0.1229.94 Quote Link to comment Share on other sites More sharing options...
yosii Posted December 16, 2012 Author Share Posted December 16, 2012 Try this: <html> <head> </head> <body> <script type="text/javascript"> function getSelectedText(elementId) { var elt = document.getElementById(elementId); if (elt.selectedIndex == -1) return null; return elt.options[elt.selectedIndex].text; } function change(num) { var text = getSelectedText('sel') document.getElementById('tex').innerHTML= 'SSS'+text[1]; } </script> <select name="godel" onchange ="change('a');" id="sel"> <option value="NUM1" >aa</option> <option value="NUM2" >bb</option> <option value="NUM3" >cc</option> </select> <br/> <div id='tex'> </div> </body> </html> tested in Chromium 22.0.1229.94 work! can you explain me why did you add id="sel" and send it to getSelectedText('sel') what this function do? thank Quote Link to comment Share on other sites More sharing options...
yosii Posted December 16, 2012 Author Share Posted December 16, 2012 NO GOOD it is work only if i want a b c i want to write full sentencses there! Quote Link to comment Share on other sites More sharing options...
kimi2k Posted December 16, 2012 Share Posted December 16, 2012 (edited) function "getSelectedText " - return text from selected option... if you whant full sentences, do this: <script type="text/javascript"> function getSelectedText(elementId) { var elt = document.getElementById(elementId); if (elt.selectedIndex == -1) return null; return elt.options[elt.selectedIndex].text; } function change() { var text = getSelectedText('sel') document.getElementById('tex').innerHTML= 'SSS'+text; } </script> <select name="godel" onchange ="change();" id="sel"> <option value="NUM1" >first line</option> <option value="NUM2" >second line</option> <option value="NUM3" >etc...</option> </select> Edited December 16, 2012 by kimi2k Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.