![]() |
| ||
| Storing a selected item into a global variable An item is selected from a list and then used as a variable in a PHP script to identify and retrieve some data from a specific record in a MySQL database. Here's the code for the select script (first a javascript external file, then an html file) : /* This is placed in an external file, addingOptions.js */ Here's the main .html code/file: <html> URL for script above: http://javascript.internet.com/forms...options-2.html You'll notice that this produces two select boxes, one with categories and one with subcategories. I'd like to be able to store the selection of a subcategory (by an end user) into a variable (I'm guessing a global variable, since I want to pass it on to a PHP script) and then take that variable and use it in a PHP script, within the main html file, in order to identify a particular record within a MySQL database. How do I do this? Any assistance will be greatly appreciated and I'll be happy to publish the final complete code once I get this thing to work. |
| ||
| Re: Storing a selected item into a global variable C'mon folks! Can't anyone help? |
| ||
| Re: Storing a selected item into a global variable Keep a hidden form element on your page which will be populated / updated whenever the user submits the form / changes the value of the secondary drop down. This hidden field can then be read using PHP at the server in the same way you read normal text fields. |
| ||
| Re: Storing a selected item into a global variable Quote:
Sounds like a good idea. If I have the following code: <select id="lstOtherStuff" multiple="multiple" size="6" style="width:200px;"> </select> and I need to pass the variable (an element in an array), "1stOtherStuff", to a PHP script, how do I do that? You mentioned putting it in a hidden form element....can you provide the syntax please? If I use the following code, I can access the file "welcome.php": <form action="welcome.php" method="post"> Id like to also use an "onclick" command to initiate the action. |
| ||
| Re: Storing a selected item into a global variable Here is a sample script (untested): <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
| All times are GMT -4. The time now is 11:53 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC