yosii Posted December 16, 2012 Share Posted December 16, 2012 Quote <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??? Link to comment https://forums.phpfreaks.com/topic/272047-change-div-value-not-work-in-chrome/ 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 Link to comment https://forums.phpfreaks.com/topic/272047-change-div-value-not-work-in-chrome/#findComment-1399636 Share on other sites More sharing options...
yosii Posted December 16, 2012 Author Share Posted December 16, 2012 On 12/16/2012 at 8:21 AM, kimi2k said: 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 Link to comment https://forums.phpfreaks.com/topic/272047-change-div-value-not-work-in-chrome/#findComment-1399637 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! Link to comment https://forums.phpfreaks.com/topic/272047-change-div-value-not-work-in-chrome/#findComment-1399641 Share on other sites More sharing options...
kimi2k Posted December 16, 2012 Share Posted December 16, 2012 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> Link to comment https://forums.phpfreaks.com/topic/272047-change-div-value-not-work-in-chrome/#findComment-1399657 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.