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 5 of 5
  1. #1
    New Coder
    Join Date
    May 2004
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing values from a list box to a text box

    I have put together a form in PHP and HTML that I want to update rather than re-write.

    At present I have a text box called country that php checks to see that it is filled in (Not Empty). It then passes that value ($country) on to the rest of the routine and adds itself to the database. Everything works fine.

    Now I want to change the form and be able to control the data that the user can enter by giving them a List Box to pick from and then pass the listbox value to the text box

    Does anyone know a simple way to do this?

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't think I understand.. do you want to use PHP for this?

    So you're going to have the list box on the same page as the text box? When the user selects an option from the list box, you want it to be automatically input into the textbox?

    If that's what you're trying to do, I would use Javascript and DOM. If you want to use PHP, you can't do this without refreshing the page (so the onChange event on the select box should submit the form consisting of the select box back to itself and the value of the select box should then be the value of the textbox..).

    I hope that made sense! But regardles, confirm what you're wanting and we can point you in the right direction.

    Sadiq.

  • #3
    New Coder
    Join Date
    May 2004
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing values from a list box to a text box

    Sorry if I've not been very clear. I'm trying to learn this stuff and am suffering from very "senior" moments.

    I want to replace the text input box with a list box on the form but have the selected option returned as if the user had typed it into the input box (as if it was still there).

    On the form at present is the input box <input type="text" name="country" size="30" value="<?php print $country ?> />.

    I want to replace this with a list box showing England, Ireland, Scotland, Wales and have the user select one and have this value passed to the PHP section as $country.

    I think it should be simple but I have totally lost the plot. If I can avoid it I want to stay away from things like Java as I having enough trouble with PHP without adding another language to the already overworked grey matter

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm not sure if I understand what you mean by replace...

    So what happens to the textbox? Ok, so you've got the list box, you make a selection. Now what? You submit the form and it goes to a PHP page and now you use the value of the list box as $country? If so, this is all:
    PHP Code:
    <select name="country">
     <
    option value="England">England</option>
     <
    option value="Ireland">Ireland</option>
     <
    option value="Scotland">Scotland</option>
     <
    option value="Wales">Wales</option>
    </
    select
    So as long as you mean that this new PHP page will be filling in the value of the textbox with $country, this should work for you.

    Let me know how that works out for you.

    Sadiq.

  • #5
    New Coder
    Join Date
    May 2004
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing values from a list box to a text box

    Thanks Saddiq,

    Got it sorted - Grey matter had turned to jelly. I'm taking the moron exam next week but will probably fail and have to stay an idiot


  •  

    Posting Permissions

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