Enjoy an ad free experience by logging in. Not a member yet?
Register .
12-16-2012, 07:57 AM
PM User |
#1
New Coder
Join Date: Jul 2012
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
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???
12-16-2012, 09:45 AM
PM User |
#2
Supreme Master coder!
Join Date: Jun 2002
Location: London, England
Posts: 17,043
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
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 ..
12-16-2012, 09:49 AM
PM User |
#3
New Coder
Join Date: Jul 2012
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by
Philip M
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
12-16-2012, 09:52 AM
PM User |
#4
Supreme Master coder!
Join Date: Jun 2002
Location: London, England
Posts: 17,043
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Quote:
Originally Posted by
yossidd
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 ..
12-16-2012, 09:53 AM
PM User |
#5
New Coder
Join Date: Jul 2012
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by
Philip M
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
12-16-2012, 10:04 AM
PM User |
#6
Supreme Master coder!
Join Date: Jun 2002
Location: London, England
Posts: 17,043
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Quote:
Originally Posted by
yossidd
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 ..
12-16-2012, 10:10 AM
PM User |
#7
New Coder
Join Date: Jul 2012
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by
Philip M
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
12-16-2012, 10:26 AM
PM User |
#8
Supreme Master coder!
Join Date: Jun 2002
Location: London, England
Posts: 17,043
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Quote:
Originally Posted by
yossidd
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.
Jump To Top of Thread
Thread Tools
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
HTML code is Off
All times are GMT +1. The time now is 05:13 AM .
Advertisement
Log in to turn off these ads.