/    Sign up×
Community /Pin to ProfileBookmark

Storing values for use in select

Hi I am trying to develop a php that uses javascript to store the selection of a radio button so i can use the value in a mysql select statement in order to dynamically created a dropdown box that corresponds with the value

my code does not work lol and it mostly looks like this:

<html>
<head>
<script type=”text/javascript>
function reload(sem)
{
var val=v;
self.location=’try.php?sem=’+ val;
}

</script>
</head>

<form name=”try” action=”tryexe.php” method=”POST”>

Choose Course Information

<BR>

Select Semester:

Fall<input type=”radio” name=”sem” value=”SP” onclick=”reload(this.value)”/>

Spring<input type=”radio” name=”sem” value=”F” onclick=”reload(this.value)”/>

<BR>
<select name=”course”>

<?php
mysql_connect(“localhost”, “root”, “****”) or die(mysql_error());

mysql_select_db(“****”) or die(mysql_error());

$s=$_GET[‘sem’];

$command=”Select Course_ID, Department, Number From COURSE Inner Join OFFERING ON COURSE.ID=OFFERING.Course_ID Where Semester=”$s”;”;

$result=mysql_query($command) or die(mysql_error());

while($row=mysql_fetch_array($result))
{
$id=$row[‘Course_ID’];
$d=$row[‘Department’];
$n=$row[‘Number’];
echo “<option value=”$id”> $d $n</option>”.”<BR>”;

}

mysql_close();

?>
</select>
</form>
</html>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@mataichiJun 19.2009 — function reload(sem)

{

var val=v;

self.location='try.php?sem='+ val;

}

What is v? I don't see where it has any value.

Does your code do anything? What is the problem you are having?

First I would check that the onclick event is firing correctly by putting something like

alert('Hello World') as the first statement in the reload function.

Then you can better figure out where the problem is.
×

Success!

Help @Dimcoz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...