Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-16-2012, 07:57 AM   PM User | #1
yossidd
New Coder

 
Join Date: Jul 2012
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
yossidd is an unknown quantity at this point
Change Div Value Not Work In Chrome

PHP Code:
<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???
yossidd is offline   Reply With Quote
Old 12-16-2012, 09:45 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,043
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Most browsers do not support onclick on a select option.

Try this:-

Code:
<script type="text/javascript"> 
function change(which) { 
document.getElementById('tex').innerHTML= "";
var val = which.value;
if (val != "") {
var valsp = val.split("~");
document.getElementById('tex').innerHTML= 'SSS'+valsp[1]; 
}
} 

</script> 
<select id="godel" onchange = "change(this)"> 
<option value = "">Select.....</option>
<option value="NUM1~a" >aa</option> 
<option value="NUM2~b" >bb</option> 
<option value="NUM3~c" >cc</option> 
</select> 

<br/> 
<div id='tex'> 
</div>
Quizmaster: What was the "Nat" in Nat King Cole short for?
Contestant: Natalie
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 12-16-2012 at 10:07 AM..
Philip M is offline   Reply With Quote
Old 12-16-2012, 09:49 AM   PM User | #3
yossidd
New Coder

 
Join Date: Jul 2012
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
yossidd is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
Most browsers do not support onclick on a select option.

Try this:-

Code:
<script type="text/javascript"> 
function change() { 
var val = document.getElementById("godel").value;
var valsp = val.split("~");
document.getElementById('tex').innerHTML= 'SSS'+valsp[1]; 
} 

</script> 
<select name="godel" onchange = "change()"> 
<option value="NUM1~a" >aa</option> 
<option value="NUM2~b" >bb</option> 
<option value="NUM3~c" >cc</option> 
</select> 

<br/> 
<div id='tex'> 
</div>
Quizmaster: What was the "Nat" in Nat King Cole short for?
Contestant: Natalie
not work man
yossidd is offline   Reply With Quote
Old 12-16-2012, 09:52 AM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,043
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by yossidd View Post
not work man
Work for me!

But better:-

Code:
<script type="text/javascript"> 
function change(which) { 
document.getElementById('tex').innerHTML= "";
var val = which.value;
if (val != "") {
var valsp = val.split("~");
document.getElementById('tex').innerHTML= 'SSS'+valsp[1]; 
}
} 

</script> 
<select id="godel" onchange = "change(this)"> 
<option value = "">Select.....</option>
<option value="NUM1~a" >aa</option> 
<option value="NUM2~b" >bb</option> 
<option value="NUM3~c" >cc</option> 
</select> 

<br/> 
<div id='tex'> 
</div>
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 12-16-2012 at 10:06 AM..
Philip M is offline   Reply With Quote
Old 12-16-2012, 09:53 AM   PM User | #5
yossidd
New Coder

 
Join Date: Jul 2012
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
yossidd is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
Wok for me!
in ff and chrome not work
here full code i wrote



PHP Code:
<html>
<
head>
</
head>
<
body>


<
script type="text/javascript"
function 
change() { 
var 
val document.getElementById("godel").value;
var 
valsp val.split("~");
document.getElementById('tex').innerHTML'SSS'+valsp[1]; 


</script> 
<select name="godel" onchange = "change()"> 
<option value="NUM1~a" >aa</option> 
<option value="NUM2~b" >bb</option> 
<option value="NUM3~c" >cc</option> 
</select> 

<br/> 
<div id='tex'> 
</div>

</body>
</html> 
not work
yossidd is offline   Reply With Quote
Old 12-16-2012, 10:04 AM   PM User | #6
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,043
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by yossidd View Post
in ff and chrome not work
here full code i wrote



PHP Code:
<html>
<
head>
</
head>
<
body>


<
script type="text/javascript"
function 
change() { 
var 
val document.getElementById("godel").value;
var 
valsp val.split("~");
document.getElementById('tex').innerHTML'SSS'+valsp[1]; 


</script> 
<select name="godel" onchange = "change()"> 
<option value="NUM1~a" >aa</option> 
<option value="NUM2~b" >bb</option> 
<option value="NUM3~c" >cc</option> 
</select> 

<br/> 
<div id='tex'> 
</div>

</body>
</html> 
not work
Compare the code I gave you with yours and spot the differences.

You must assign an id to the select list, not just a name.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 12-16-2012 at 10:09 AM..
Philip M is offline   Reply With Quote
Old 12-16-2012, 10:10 AM   PM User | #7
yossidd
New Coder

 
Join Date: Jul 2012
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
yossidd is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
Compare the code I gave you with yours and spot the differences.

You must assign an id to the select list, not just a name.
thank man!!
i will be happy if you can explain what is the diffrent between my code that i can learn
yossidd is offline   Reply With Quote
Old 12-16-2012, 10:26 AM   PM User | #8
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,043
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by yossidd View Post
thank man!!
i will be happy if you can explain what is the diffrent between my code that i can learn
As I say, compare the code I gave you with yours and spot the differences.

You need an initial option "Select..." to allow the function to trigger onchange. Otherwise the user cannot select option aa.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:13 AM.


Advertisement
Log in to turn off these ads.