Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jul 2012
    Posts
    12
    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???

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,917
    Thanks
    203
    Thanked 2,531 Times in 2,509 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
    Last edited by Philip M; 12-16-2012 at 10:07 AM.

    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.

  • #3
    New Coder
    Join Date
    Jul 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,917
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    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>
    Last edited by Philip M; 12-16-2012 at 10:06 AM.

    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.

  • #5
    New Coder
    Join Date
    Jul 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,917
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    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.
    Last edited by Philip M; 12-16-2012 at 10:09 AM.

    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.

  • #7
    New Coder
    Join Date
    Jul 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,917
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •