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 9 of 9
  1. #1
    Regular Coder
    Join Date
    Sep 2010
    Posts
    122
    Thanks
    6
    Thanked 0 Times in 0 Posts

    combo box value not getting

    hi i have this coding

    <script type="text/javascript">


    function getCombo1(sel) {
    var value = sel.options[sel.selectedIndex].value;

    if(value = "Value1")
    {

    document.getElementById('t1').value =5;


    }
    }

    </script>
    <select id="combo1" onchange="getCombo1(this)">
    <option value="">Select combo</option>
    <option value="Value1">Text1</option>
    <option value="Value2">Text2</option>
    <option value="Value3">Text3</option>
    </select>

    <input name="" type="t1" />


    i hear what i want to do is the when selecting combo box text1 text box will be 5


    plz help me to do this


    sample coding plzzzzzzzzzzz

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    <input name="t1" id="t1" type="text" />
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #3
    Regular Coder
    Join Date
    Sep 2010
    Posts
    122
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by WolfShade View Post
    <input name="t1" id="t1" type="text" />
    still i cant solve the problem plese help me

  • #4
    Regular Coder
    Join Date
    Sep 2010
    Posts
    122
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by WolfShade View Post
    <input name="t1" id="t1" type="text" />
    <script type="text/javascript">


    function getCombo1(sel) {
    var value = sel.options[sel.selectedIndex].value;

    if(value = "Value1")
    {

    document.getElementById('t1').value =5;


    }
    }

    </script>
    <select id="combo1" onchange="getCombo1(this)">
    <option value="">Select combo</option>
    <option value="Value1">Text1</option>
    <option value="Value2">Text2</option>
    <option value="Value3">Text3</option>
    </select>

    <input name="t1" type="t1" />


    plz help me to solve this

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    As wolfshade has told you, <input type = "text" name="t1" id = "t1">

    document.getElementById() requires that the element has an id.

    With the alteration above the code works.


    It's a 32-team tournament and all but one or two are in the Fifa top-20 rankings. - Commentator Sky Sports News

    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.

  • #6
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Quote Originally Posted by coolumanga View Post
    <input name="t1" type="t1" />
    The object has to have an ID, and the type needs to be TEXT.

    <input name="t1" id="t1" type="text" />
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #7
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,592
    Thanks
    0
    Thanked 645 Times in 635 Posts
    If you are trying to set up a combo box then it is far easier to do it with a text input field and a list and not use a select at all in HTML4 (you still need to use JavaScript to connect the two).

    You can use a <datalist> with your text input field to fully define a combobox in HTML5.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #8
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,065
    Thanks
    36
    Thanked 497 Times in 491 Posts

    Lightbulb

    This will not do what you expect it to do ...
    Code:
    ...
    if (value = 'Value1') {
    ...
    Should be:
    if (value == 'Value1') {

  • #9
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,592
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Quote Originally Posted by jmrker View Post
    This will not do what you expect it to do ...
    Code:
    ...
    if (value = 'Value1') {
    ...
    Should be:
    if (value == 'Value1') {
    A safer way to code comparisons with static strings is to put the string first - that way if you accidentally leave out an = you get a syntax error instead of the code doing the wrong thing.

    Also using == is considered to be poor coding in JavaScript - you should use === instead.

    if ('Value1' === value)
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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