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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Dropdown onclick syntax error 1

Status
Not open for further replies.

RPGguy

Programmer
Jul 27, 2001
73
0
0
US
I have a table containing members of a boy's choir. There are 4 types of claases within the choir. My PHP script lists the members fine. I have a field that I want to use to filter the list by whatever choir type the user selects. I fill the dropdown dynamically from a table of choir types. Ideally when the user selects a choir type I would automatically call the same script and pass the selection as a variable in the URL. I use <? echo StripSlashes($line5[memChoir]); ?> as the variable to pass since that is the value I see in the dropdown. Here is the code I'm using for the drop down:

<? $where="memberlist.php?where"; ?>
//this is at the top of the script

<td width="43%" align="left" size="15" valign="baseline">for Choir <select size="1" name="selchoir" tabindex="1"
onchange="window.location = $where .<? echo StripSlashes($line5[memChoir]); ?>">
<option selected><? echo StripSlashes($line5[memChoir]); ?></option>

<?php
$query = "SELECT Value FROM tblTableV where Name='CHOIR' order by Value";
$result5 = mysql_query($query);

while ($line5 = mysql_fetch_array($result5))
{
?>
<option><? echo StripSlashes($line5[Value]); ?></option>
<?
}
mysql_close($link);
?>
</select></td>

When I select a drop down value the page does not call itself. I know it's probably a simple syntax error but I am at my wits end. As always, thanks in advance for your help.

Scott
 
Try this:
Code:
<? $where="memberlist.php?where="; ?>
[...]
<select size="1" name="selchoir" tabindex="1" onchange="document.location.href='<?= $where . StripSlashes($line5[memChoir]) ?>';">
[...]

I haven't tested it, but it should fix a few errors.

Take Care,
Mike
 
The only problem now is when the page calls itself no value is being placed in the URL. Here's the latest code:

$where="ssmemberlist.php?where="; - previously defined

<td width="43%" align="left" size="15" valign="baseline">for Choir <select size="1" name="selchoir" tabindex="1"
onchange="document.location.href='<?= $where . StripSlashes($line5[Value]) ?>';">
<option selected><? echo StripSlashes($line5[value]); ?></option>

<?php
$query = "SELECT Value FROM tblTableV where Name='CHOIR' order by Value";
$result5 = mysql_query($query);

while ($line5 = mysql_fetch_array($result5))


{
?>
<option><? echo StripSlashes($line5[Value]); ?></option>

<?
}
mysql_close($link);
?>
</select></td>

The URL shows:

The dropdown box shows my selection so I would think
StripSlashes($line5[value]) would contain the value selected.
 
See if this will help you out any further.
Code:
<?php
	$where="ssmemberlist.php?where=";
?>
<td width="43%" align="left" size="15" valign="baseline">
	for Choir
	<select size="1" name="selchoir" tabindex="1" onchange="document.location.href = '?where=' + this.options[this.selectedIndex].value;">
		<option></option>
<?php
	$query = "SELECT Value FROM tblTableV where Name='CHOIR' order by Value";
	$result5 = mysql_query($query);
	while ($line5 = mysql_fetch_row($result5))
	{
		if ($line5[0] == $_GET['where']) {$s_selected = " selected='selected'";}
		else {$s_selected = '';}
?>
		<option value="<?= $line5[0]; ?>"<?= $s_selected ?>><?= $line5[0]; ?></option>
<?
	}
	mysql_close($link);
?>
	</select></td>

Personally, I would recommend to read up on remote scripting / AJAX. It would be far more user-friendly; and once you get the hang of it, pretty easy to implement.

Take Care,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top