--- "Carl J. Hixon" <[EMAIL PROTECTED]> wrote:
> 
> > Carl, I couldnt even get that site to come up at all so, Im going to 
> > make some guesses here.
> 
> So sorry, I had a typo in the url:
> http://www.cgi-interactive-uk.com/populate_combo_box_function_php.html
> 
> > 1. You want to populate a combo box.
> >     You know how to do that now.
> 
> Lets pause here.  I can populate the combobox from the database (just
> like on the example site) but I don't know how to do the next step. 
> Use the data from the combo box?  I don't even know what variable is
> being set when I pick something in the combobox so I don't know what
> would go into the submit button.  I realize I need a submit button, I
> can probably figure it out from the books that I have but I can't
> identify the variable...  I know that's pretty sad...

OK.  Here are some basics.  The HTML tag is a <select> element with nested
<option> elements.  A basic example looks like this:

<form method='post' action='script.php'>
<select name='var'>
  <option value='v1'>Value 1</option>
  <option value='v2'>Value 2</option>
  <option value='v3'>Value 3</option>
  <option value='v4'>Value 4</option>
</select>
<input type='submit' value='Button Label'>
</form>

In the example above, v1-v4 are the values sent to the PHP variable
$_POST['var'] based on the user's selection.  Value 1-Value 4 are the labels
seen on the select list.  

The submit button gathers the data collected in the form (the select list in
this case) and packages it via the POST method (or GET if you prefer to have
variables go in the URL) and sends it to the PHP script identified in the
action property of the <form> element.

To get this list to be populated by a database query, you would send the query
and output the lines for the <option> element for each row in the result set.

> > 2. You want to allow someone to make an addition to that box. And when 
> > that is accepted, you want to do what? Put that new value into the db?
> 
> I will probably just add a button for adding a new item to the list. 
> Better to figure out the basics before running off and trying to get
> too fancy.

There are a number of ways this could be achieved.  If your form was simple and
you didn't mind a page reload you could put the new value in an <input
type='text'> element and when the value is received by the script, it would be
inserted into the DB table for use the next time the select button is
displayed.

If you want a very dynamic change, you will need to use Javascript to notice
when a value is in the text box and the "add" button clicked.  You would then
need to append an <option> element among the existing list of elements.  You'd
also have to add this to the DB table, probably when the form data is submitted
so it would be available.  This is tricky and probably more difficult than it's
worth.  One thing to look at is "remote scripting" which can achive this sort
of result but is tricky to program and harder to debug.

This kind of question usually comes from someone who has programmed or used
programs created for the desktop.  The web, because of its client-server nature
and the fact that PHP runs on the server and is executed completely before the
page shows up in the web browser.  As such, it can't respond to user events in
the browser.  Javascript runs in the browser and can respond to these events. 
It is not easy to get Javascript to call a PHP script.  It can be done with the
remote scripting that I mentioned above along with the little-used and
little-known Javascript XMLHttpRequest object.

James
_____


James D. Keeline
http://www.Keeline.com  http://www.Keeline.com/articles
http://Stratemeyer.org  http://www.Keeline.com/TSCollection

http://www.ITeachPHP.com -- Free Computer Classes: Linux, PHP, etc.
Spring Semester Begins Jan 31 -- New Classes Start Every Few Weeks.


Community email addresses:
  Post message: [email protected]
  Subscribe:    [EMAIL PROTECTED]
  Unsubscribe:  [EMAIL PROTECTED]
  List owner:   [EMAIL PROTECTED]

Shortcut URL to this page:
  http://groups.yahoo.com/group/php-list 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-list/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to