SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2001
    Brooklyn, NY
    0 Post(s)
    0 Thread(s)

    populate listbox from textox, possible?

    Im more of a php kind of guy, so i hope i can explain this properly.

    Currently, on a form I've made, a select listbox is displayed right next to a textbox. The listbox is populated with data brought over from the database. When a user goes to fill out the form, they look in the listbox, and if the correct option is not there, then they click a checkbox and type it into the textbox.

    With me so far? Good. So when the user hits the submit button, i check to see if the checkbox is checked, and enter the data from the textbox into the database. That way, on the next go-round with the form, it will be displayed to the user in the listbox.

    What I would ultimately like to do is streamline the process, so that when text is entered into a textbox and a button is clicked, it will add the data into the database and repopulate (refresh) the listbox. Then the user could select the option immediately from the listbox.

    Is this possible? I've looked over various sites and havent really found an example that does what i'd like. Hopefully someone out there can help me


  2. #2
    SitePoint Addict
    Join Date
    May 2000
    0 Post(s)
    0 Thread(s)
    Not sure how this would work with the DB side, but here is one way to do it with JavaScript.
    <TITLE>Dropdown create</TITLE>
    <SCRIPT LANGUAGE="JavaScript">
    NS = document.layers? 1:0;
    function populate(formobj)
    var len=formobj.selopt.length
    var optval=formobj.txtbx.value
    var newoption=new Option(optval,optval)
    if (NS)
    <H3>Select a color</H3>
    <FORM NAME="myform">
    Enter your color here: <INPUT TYPE="text" NAME="txtbx" SIZE="10">
    Check here to add it to the Drop box <INPUT TYPE="checkbox" NAME="sel" onClick="populate(this.form)">
    <SELECT NAME="selopt">
    <OPTION VALUE="Dark Green">Dark Green</OPTION>
    <OPTION VALUE="Light Green">Light Green</OPTION>

    Hope this helps and good luck!


Posting Permissions

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