Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call php function from radio button click

Status
Not open for further replies.

mancroft

Programmer
Oct 26, 2002
267
GB
Call php function from radio button click



I am creating two sets of three radio buttons (small, medium, large) and (red, green, blue) plus a function to display the item id number so when a radio button is clicked an item id number for that combination of sizes/colors is shown.



The code to display the item id is in function showid() as seen below:



QUESTION



How do I get it so that function showid() is called when a radio button is clicked?



Code:
<table>
<tr>

<form>

<td>
<?
include("testdb.php");


MYSQL_CONNECT(HOST,USER,PASS) OR DIE("Unable to connect to database"); 

@mysql_select_db(DB) or die( "Unable to select database");

$query=("select * from categories order by color desc");

$result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() ); 

$selectedflag1= 1;

while($row=mysql_fetch_array($result)){ 
$color = @$row["color"];

if ($selectedflag1== 1){
$selected1 = "checked";}
else{
$selected1 = "";
}


echo " <input type=\"radio\" name=\"color\" value=\"$color\" $selected1  >$color";
echo "<br>";
$selectedflag1 = 2;
}


?>

</td>
<td>
<?
$query=("select * from categories order by size desc");

$result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() ); 

$selectedflag2= 1;

while($row=mysql_fetch_array($result)){ 
$size = @$row["size"];


if ($selectedflag2== 1){
$selected2 = "checked";}
else{
$selected2 = "";
}

echo " <input type=\"radio\" name=\"size\" value=\"$size\" $selected2 >$size";
echo "<br>";
$selectedflag2= 2;


}

?>

</td>
<td>

<?

function showid(){



$query=("select itemID from inventory WHERE itemColor = '$color' AND itemSize = '$size'");

$result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() ); 


$querydata = mysql_fetch_array($result);



$theitemID = $querydata["itemID"];



echo("$theitemID");


}

?>

</td>
</form>
</tr>
</table>
 
You can't.

PHP runs on the server. You're trying to do things with client-side scripting. You either need to program that functionality in JavaScript or VBScript. JavaScript and VBScript are beyond the topic of this forum.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
radioclicks cannot activate PHP code without a roundtrip to the server. The OnClick would need to submit a form to pass the required values back to the server and have php process them...

onClick="document.forms['form name'].submit();"

hth


Bastien

Cat, the other other white meat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top