| | |
Onclick to pass a variable to a PHP script
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2008
Posts: 11
Reputation:
Solved Threads: 0
If I have the following code:
<form>
.
.
.
<select id="lstOtherStuff" multiple="multiple" size="6" style="width:200px;">
</select>
</form>
and I need to pass the variable "1stOtherStuff" (which is an element in an array) to a PHP script, how do I do that?
If I use the following code, I can access the file "welcome.php" (where I'd run a MYSQL script to query a value from a database):
<form action="welcome.php" method="post">
Would there be another way to access this file, "welcome.php"?
Or can I put the PHP script immediately after the Select script?
I would like to also use an "onclick" command to initiate the action. So the user would press a button, after making a selection (the selection would then be stored in the variable
"1stOtherStuff"). The selected value would then be sent to the PHP script and the PHP script would "echo" the value back.
The main question I have though is how do I pass the variable, "1stOtherStuff", to the PHP/MySQL script...
Your help would be appreciated!
<form>
.
.
.
<select id="lstOtherStuff" multiple="multiple" size="6" style="width:200px;">
</select>
</form>
and I need to pass the variable "1stOtherStuff" (which is an element in an array) to a PHP script, how do I do that?
If I use the following code, I can access the file "welcome.php" (where I'd run a MYSQL script to query a value from a database):
<form action="welcome.php" method="post">
Would there be another way to access this file, "welcome.php"?
Or can I put the PHP script immediately after the Select script?
I would like to also use an "onclick" command to initiate the action. So the user would press a button, after making a selection (the selection would then be stored in the variable
"1stOtherStuff"). The selected value would then be sent to the PHP script and the PHP script would "echo" the value back.
The main question I have though is how do I pass the variable, "1stOtherStuff", to the PHP/MySQL script...
Your help would be appreciated!
•
•
•
•
and I need to pass the variable "1stOtherStuff" (which is an element in an array) to a PHP script, how do I do that?
$select_value = $_REQUEST['1stOtherStuff']; Here is a simple example. php Syntax (Toggle Plain Text)
<?php $selected_value = $_REQUEST['select']; echo "Selected value is ". $selected_value; ?> <html> <body> <form name="form1" method="post" action="onchange.php"> <select name="select" onchange="javascript: document.form1.submit();"> <option value=1>1</option> <option value=2>2</option> <option value=3>3</option> </select> <input type="button" name="button" value="Click me too!"> </form> </body> </html>
php Syntax (Toggle Plain Text)
<?php if(isset($_REQUEST['submit'])) { $selected_value = $_REQUEST['select']; echo "Selected value is ". $selected_value; } ?> <html> <body> <form name="form1" method="post" action="onchange.php"> <select name="select"> <option value=1>1</option> <option value=2>2</option> <option value=3>3</option> </select> <input type="submit" name="submit" value="Submit"> </form> </body> </html>
Last edited by nav33n; Jun 24th, 2008 at 2:09 pm.
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
@mgt:
Don't create multiple threads for the same topic. It ends up wasting the time of people who reply to those threads thinking there was no reply given.
Don't create multiple threads for the same topic. It ends up wasting the time of people who reply to those threads thinking there was no reply given.
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
![]() |
Similar Threads
- how to pass one script to another using php,mysqldatabase (PHP)
- value pass from one script to another script (JavaScript / DHTML / AJAX)
- want to pass php variable to javascript (PHP)
- Send variable from javascript to php? (PHP)
- pass the value to the text box (JavaScript / DHTML / AJAX)
- get html element value using php (PHP)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Storing a selected item into a global variable
- Next Thread: Trim spaces
Views: 8003 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxexample ajaxjspservlets array autoplay blackjack browser captcha captchaformproblem cart child class close codes date debugger dependent developer disablefirebug dom editor element embed engine enter events explorer ext file firefox flash focus form forms game gears getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe java javascript javascripthelp2020 jquery jsf jsp jump libcurl maps margin marquee masterpage math media menu object onerror onmouseoutdivproblem onreadystatechange parent passing paypal pdf php player position post programming prototype rated redirect safari scale scriptlets scroll search security size software solutions sources star stars stretch synchronous toggle tweet unicode variables web webkit webservice window \n






