Dropdown list PHP/Javascript confusion
Posted: Sat Feb 07, 2004 4:55 pm
Hi everyone
I've been baffled by this problem all day. It's a simple one but the problem is that so am I.
I've got a dropdown list (static) that I want to query a database depending on the option the user selects from the list.
I've got a Javascript as such that dynamically sets the text of the selected option to a variable txt:
The Javascript is run when the form containing the dropdown list is submitted:
The problem is that I now don't know how to run a query like the one below depending on the selected text:
I've got the page up at http://www.cyberiapc.com/jokes.php and what I'd like to do is allow visitors to choose to display jokes from only a certain category. I know that Javascript is client-side and PHP is server-side, and so that might be what's confusing me.
Thanks for any pointers.
I've been baffled by this problem all day. It's a simple one but the problem is that so am I.
I've got a dropdown list (static) that I want to query a database depending on the option the user selects from the list.
I've got a Javascript as such that dynamically sets the text of the selected option to a variable txt:
Code: Select all
<script language="JavaScript">
function chkForm()
{
txt=document.formsї0].category.optionsїdocument.formsї0].category.selectedIndex].text;
}
</script>Code: Select all
<form action="<? echo($PHP_SELF); ?>"onChange="chkForm()"; method="post">
<select name="category" value="category">
<option value="All" selected>All</option>
<option value="General">General</option>
<option value="Microsoft">Microsoft</option>
<option value="Programming">Programming</option>
<option value="Helpline">Helpline</option>
</select><input type="submit" value="Go!" name="submit"><br><br>
</form>Code: Select all
$sql="select id,author,title,joke,category,approved from jokes WHERE category=txt";Thanks for any pointers.