Jump to content

send data with link to a new page


houssam_ballout

Recommended Posts

Hello all,The code below is for selecting the search criteria, the question that I'd:near each select box there is a search click, so that the user can click on it and search for the things that he/she want, I want to know what did the user chose from the select box when he click the search?thanks

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title></head><body><table border="1"><form name="search" method="post"><?phpinclude('conn.php');$username = $_GET['username'];//Select all Majors$sql1 = "select * from majors";$result1 = mysql_query($sql1) or die(mysql_error());echo "<tr>";echo "<td>Major Name</td>";echo "<td><select name='major'>";while($row1 = mysql_fetch_array($result1)){ echo "<option>". $row1['name'] ."</option>";}$text = $_POST['major'];echo $text;echo "</select></td><td><a href='search.php?search=major&text=\'$text\''>search</a></td></tr>";//Select all Universities$sql2 = "select * from lebaneseuniversities";$result2 = mysql_query($sql2) or die(mysql_error());echo "<tr>";echo "<td>Universtiy Name</td>";echo "<td><select name='university'>";while($row2 = mysql_fetch_array($result2)) echo "<option>". $row2['smallname'] ."</option>";echo "</select></td><td><a href='search.php?search=university'>search</a></td></tr>";//Locationecho "<tr>";echo "<td>Location</td>";echo "<td><select name='branch'>";echo "<option>Fidar-Halat</option>";echo "<option>Beirut</option>";echo "<option>Saida</option>";echo "<option>Ashrafieh</option>";echo "<option>Koura</option>";echo "<option>Hariss</option></td>";echo "</select>";echo "</td><td><a href='search.php?search=location'>search</a></td></tr>";//Tuition Limits$sql3 = "select distinct Tuition from lebaneseuniversities";$result3 = mysql_query($sql3) or die(mysql_error());echo "<tr>";echo "<td>Tuition Range</td>";echo "<td><select name='tuition'>";while($row3 = mysql_fetch_array($result3)) echo "<option>". $row3['Tuition'] ."</option>";echo "</select></td><td><a href='search.php?search=Tuition'>search</a></td></tr>";?></form></table></body></html>
Link to comment
Share on other sites

  • 2 weeks later...

The search link will need to run a Javascript function that will send the value of the box to the next page. You can have it look up the value and put it on the end of the URL as a querystring variable, or set the value of a hidden form element and submit a form. Since you already have a form around everything you'll probably need to append the value to the URL.e.g.

<script type="text/javascript">function do_search(theurl, elId){  var val = document.getElementById(elId).value;  if (theurl.indexOf("?") == -1)	theurl += "?";  else	theurl += "&";  theurl += "q=" + val;  window.location.href = theurl;  return false;}</script><a href='search.php?search=location' onclick='return do_search(this.value, "branches");'>search</a>

That will append the value of an element to the URL with the variable name q. Make sure to assign an ID to the element you're trying to get the value of.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...