SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2001
    Location
    Brooklyn, NY
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    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

    Thanks.

  2. #2
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure how this would work with the DB side, but here is one way to do it with JavaScript.
    <HTML>
    <HEAD>
    <TITLE>Dropdown create</TITLE>
    <SCRIPT LANGUAGE="JavaScript">
    NS = document.layers? 1:0;
    function populate(formobj)
    {
    if(formobj.txtbx.value.length>0)
    {
    var len=formobj.selopt.length
    var optval=formobj.txtbx.value
    var newoption=new Option(optval,optval)
    formobj.selopt.options[len]=newoption
    if (NS)
    {
    history.go(0)
    }
    }
    }
    </SCRIPT>
    <BODY>
    <H3>Select a color</H3>
    <FORM NAME="myform">
    Enter your color here: <INPUT TYPE="text" NAME="txtbx" SIZE="10">
    <br>
    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>
    </SELECT>
    </FORM>
    </BODY>
    </HTML>

    Hope this helps and good luck!


Bookmarks

Posting Permissions

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