I'm pretty new to php and html programming.
I'm struggeling for days allready with the following question:
I have a phpscript that prepares a form. in that form there are select statements based on output from a database:
echo ' <tr>';
echo ' <td> CI ID </td>';
echo ' <td><select name = "ci_id">';
$query = "select id from ci";
$result= mysql_query($query);
$num_results = mysql_num_rows($result);
for ($i=0; $i < $num_results; $i++)
{
$row = mysql_fetch_array($result);
$ci_id=htmlspecialchars( stripslashes($row["id"]));
echo ' <option value ="'.$ci_id.'">'.$ci_id;
}
echo ' </select></td>';
echo ' </tr>';
the ci_id's found are just what they say: id's from a tableentry in a database.
There are more constructions like this in the form.
I now want to give the user a possibility to press an infobutton right behind the selection button. And when he presses it I want to represent to him the rest of the entry from the database so that he can see what belongs to the id he wants to chose.
I don't mind if it has to be via the onClick button and a php script , or via a URL to a php script or whatever. I just want to know how I can grab back the above $ci_id to be able to process that data.
I tried:
echo " <td><button onClick=\"window.open('test.php')\">Info </button></td>";
b4 the </tr>
it does call my script in a new window but:
<?php
echo 'Configuration_ID='.$HTTP_POST_VARS["ci_id"].'<BR>';
echo 'Configuration_ID='.$HTTP_GET_VARS["ci_id"].'<BR>';
?>
in that script only give empty , so it looks like it is impossible to process vars from within the form b4 the submit has been pressed.
Is there an elegant solution to do this ????
Thanx in advance
passing vars from within a form with the onClick button even
Moderator: General Moderators
- gite_ashish
- Forum Contributor
- Posts: 118
- Joined: Sat Aug 31, 2002 11:38 am
- Location: India
hi,
make it like:
and in the test.php you can access it like:
make it like:
Code: Select all
<?php
echo "<TD><INPUT type=button onClick="window.open('test.php?ci_id=$ci_id')"></TD>";
?>Code: Select all
<?php
echo 'Configuration_ID=' . $HTTP_GET_VARSї"ci_id"] . '<BR>';
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
By 'new PHP' Takuma means PHP version 4.1 or up.
For more information:
http://www.devnetwork.net/forums/viewtopic.php?t=511
and
http://www.php.net/manual/en/language.v ... efined.php
Mac
For more information:
http://www.devnetwork.net/forums/viewtopic.php?t=511
and
http://www.php.net/manual/en/language.v ... efined.php
Mac
hi, thanks fro the answers. I forgot the mention all what I tried.
The php.? solution I also tried ofcourse.
it doesn't give the solution, since for some reason I think that whatever I click or fill in in the form, is only put into the vars (in this case the $ci_id) untill AFTER I have pressed the "submit" button.
it doesn't matter how often I press the selct button, or what number I chose, it just stays empy when it arrives in the onClick script
Further the reason why I use HTTP_GET_VARS insteda of _GET is because I at home use the new version, but at work they still have the old, and _GET is not backwards compatible, while HTTP_GET_VARS is
The php.? solution I also tried ofcourse.
it doesn't give the solution, since for some reason I think that whatever I click or fill in in the form, is only put into the vars (in this case the $ci_id) untill AFTER I have pressed the "submit" button.
it doesn't matter how often I press the selct button, or what number I chose, it just stays empy when it arrives in the onClick script
Further the reason why I use HTTP_GET_VARS insteda of _GET is because I at home use the new version, but at work they still have the old, and _GET is not backwards compatible, while HTTP_GET_VARS is
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Which is fair enough. You did say that you were very new to PHP which could mean that you were not aware of the new variables, you'd be surprised just how many people aren't...coolen wrote:Further the reason why I use HTTP_GET_VARS insteda of _GET is because I at home use the new version, but at work they still have the old, and _GET is not backwards compatible, while HTTP_GET_VARS is.
Mac
For ppl that want to know how, I solved it myself. The vars used are known in javascript, so they can be reached there, It is indeed so that if you haven't submitted the form then the select variable is NOT filled.
So I did pur a piece of javascript in the header:
<html>
<head>
<SCRIPT type="text/JavaScript">
function show_configuration_info()
{
var cf_id="get_configuration.php?cfg_id="+document.form.configuration_id.options[document.form.configuration_id.selectedIndex].value;
window.open(cf_id,"info");
}
</SCRIPT>
And now the info button declared later wil (when clicked) redirect to the chosen info from the selection-options list:
echo ' <tr>';
echo ' <td> Configuration ID </td>';
echo ' <td><select name = "configuration_id">';
$query = "select id from configuration";
$result= mysql_query($query);
$num_results = mysql_num_rows($result);
for ($i=0; $i < $num_results; $i++)
{
$row = mysql_fetch_array($result);
$cfg_id=htmlspecialchars( stripslashes($row["id"]));
if ($i==0) {
echo ' <option value ="'.$cfg_id.'" selected>'.$cfg_id;
} else {
echo ' <option value ="'.$cfg_id.'">'.$cfg_id;
}
}
echo ' </select>';
echo ' <input type="button" name="infoButton2" value="Info" onclick="show_configuration_info()"></td>';
echo ' </tr>';
So I did pur a piece of javascript in the header:
<html>
<head>
<SCRIPT type="text/JavaScript">
function show_configuration_info()
{
var cf_id="get_configuration.php?cfg_id="+document.form.configuration_id.options[document.form.configuration_id.selectedIndex].value;
window.open(cf_id,"info");
}
</SCRIPT>
And now the info button declared later wil (when clicked) redirect to the chosen info from the selection-options list:
echo ' <tr>';
echo ' <td> Configuration ID </td>';
echo ' <td><select name = "configuration_id">';
$query = "select id from configuration";
$result= mysql_query($query);
$num_results = mysql_num_rows($result);
for ($i=0; $i < $num_results; $i++)
{
$row = mysql_fetch_array($result);
$cfg_id=htmlspecialchars( stripslashes($row["id"]));
if ($i==0) {
echo ' <option value ="'.$cfg_id.'" selected>'.$cfg_id;
} else {
echo ' <option value ="'.$cfg_id.'">'.$cfg_id;
}
}
echo ' </select>';
echo ' <input type="button" name="infoButton2" value="Info" onclick="show_configuration_info()"></td>';
echo ' </tr>';