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
    Regular Coder
    Join Date
    Feb 2005
    Posts
    190
    Thanks
    25
    Thanked 0 Times in 0 Posts

    Insert text in textbox upon selecting list value

    hi

    could someone help me to insert a piece of text in a text box when the user selects a particular value in a list field.

    thanks

    vorl

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    At the most rudimentary...

    <select onchange="doIt()" ...>

    Code:
    function doIt()
       {
       document.formname.elementname.value='some text value';
       }

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Nikki is correct, as an addendum this example would insert the value of the select box into the text field.
    Code:
    <select onchange="document.theFormName.theTextBoxName.value=this.options[this.selectedIndex].value;">
    m_n
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #4
    Regular Coder
    Join Date
    Feb 2005
    Posts
    190
    Thanks
    25
    Thanked 0 Times in 0 Posts
    thanks

    i have 'yes' and 'no' in the list. I only want the text to be inserted in the textbox when 'no' is selected. how would i do this?

    thanks again

    vorl

  • #5
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Code:
    <select onchange="if(this.options[this.selectedIndex].value=='no'){document.theFormName.theTextBoxName.value='no'}">
    "">
    hope this helps

    m_n
    Last edited by martin_narg; 08-14-2005 at 04:19 PM.
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #6
    Regular Coder
    Join Date
    Feb 2005
    Posts
    190
    Thanks
    25
    Thanked 0 Times in 0 Posts
    Hey Martin

    sorry to be of nuisence but when i add the code a error appears which says there is a ')' missing. But i dont know where to put it; please show me where to put it?

    Thanks again

    vorl

  • #7
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Humble apologies, the error was in my code i posted, i missed out the closing ) of the if statement.

    try this:
    Code:
    <select onchange="if(this.options[this.selectedIndex].value=='no'){document.theFormName.theTextBoxName.value='no'}">
    "">
    apols

    m_n
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #8
    Regular Coder
    Join Date
    Feb 2005
    Posts
    190
    Thanks
    25
    Thanked 0 Times in 0 Posts
    thanks mate that totally worked!!

    thanks for being patient

    vorl


  •  

    Posting Permissions

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