CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2004
    Location
    .hell On Earth.
    Posts
    91

    From <Select> to Textbox

    Hello,

    I got the following html

    Code:
    <select id="P_City" tabindex="9" onSelect="JCopyField()" >
        <option value="1">Boston</option>
        <option value="2">Ithaca</option>
        <option value="3">New York</option>
    </select>
    
      <input name="" type="text" id="E_City">
    What i want is when a user chooses one of the cities from the list.. it should show up in the textbox.. so i wrote the JCopyField() function as follows

    Code:
    Function JCopyField(){
    
    document.T_Form.getElementById('E_City').value = document.T_Form.getElementById('P_City').value;
    }

    But it does not work.. can anyone take the bug out.. its driving me buts

    regards,
    kimoo.

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: From <Select> to Textbox

    That's because it's just document.getElementById(). Don't call the form. Also, I would recommend downloading Firefox and using their JavaScript debugger. It will help you greatly.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Sep 2004
    Location
    .hell On Earth.
    Posts
    91

    Re: From <Select> to Textbox

    Downloaded JavaScript debugger...kind of cool.

    The problem seems to be the HTML not the JavaScript.

    EDIT: Accidentally edited instead of quoting.
    Last edited by PeejAvery; July 2nd, 2007 at 02:29 PM.

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: From <Select> to Textbox

    Your problem is the HTML. You have onselect in your select tag. Use onchange.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Sep 2004
    Location
    .hell On Earth.
    Posts
    91

    Re: From <Select> to Textbox

    i can not believe that i had been trying to debug such a mistake for sooo long..

    Guess what even onChange does not work.. and i am still trying to find out why

    gonna break my box today :$

    kimoo

  6. #6
    Join Date
    Sep 2004
    Location
    .hell On Earth.
    Posts
    91

    Angry Re: From <Select> to Textbox

    NOOOOOOOOOOOOOO

    the problem was in two things

    1. onSelect had to be onChange

    2. Guess this just guess the 'F' of the word function in the Javascript was UpperCase and it had to be LowerCase

    OMG ~ i just love programming..

    kimoo

  7. #7
    Join Date
    May 2002
    Posts
    10,943

    Re: From <Select> to Textbox

    Quote Originally Posted by kimoo
    2. Guess this just guess the 'F' of the word function in the Javascript was UpperCase and it had to be LowerCase
    What I said was correct with the onchange. Funny though, I didn't event thing about F instead of f. Sometimes you just look over things.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  8. #8
    Join Date
    Nov 2005
    Posts
    49

    Re: From <Select> to Textbox

    I think to get value from select element first you to get its selected index and then from options array get its value. For example
    Code:
     <select name="abc" id="abc" onchange="showSelectedValue()">
     <option value="A">A
    <option value="B">B
    <option value="C">C
    </select>
    function showSelectedValue()
    {
       var selectedIndex = document.getElementById('abc').selectedIndex;
       alert(document.getElementById('abc').options[selectedIndex].value);
    }
    Muhammad Waqas Badar

  9. #9
    Join Date
    May 2002
    Posts
    10,943

    Re: From <Select> to Textbox

    Quote Originally Posted by Waqas_Badar
    I think to get value from select element first you to get its selected index and then from options array get its value.
    You miss the point. The point was to fill the textbox when a user selects something from the drop-down. Not alter the drop-down by using JavaScript.

    Anyway, the issue has already been resolved.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured