Jump to content

Change Div Value Not Work In Chrome


yosii

Recommended Posts

<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
Share on other sites

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
Share on other sites

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
Share on other sites

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 by kimi2k
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.