Jump to content

How to implement an pulldown menu


Muiter

Recommended Posts

Ok I have sorted some things out and the basic script is working. But how do I implement this in my php files?

It's AJAX script but I have an problem with php so I have posted it in this forum.

The original script can be found here: http://www.weberdev.com/get_example-4389.html

 

test.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 

<html> 
<head> 
<title>Customer Account Information</title> 
<script type="text/javascript"> 
	var url = "zoek_offerte_order.php?id="; // The server-side script 
   function handleHttpResponse() {	
	if (http.readyState == 4) { 
		  if(http.status==200) { 
			  var results=http.responseText; 
		  document.getElementById('divCustomerInfo').innerHTML = results; 
		  } 
		  } 
	} 

	function requestCustomerInfo() {	  
		var sId = document.getElementById("txtCustomerId").value; 
		http.open("GET", url + escape(sId), true); 
		http.onreadystatechange = handleHttpResponse; 
		http.send(null); 
	} 
function getHTTPObject() { 
  var xmlhttp; 

  if(window.XMLHttpRequest){ 
xmlhttp = new XMLHttpRequest(); 
  } 
  else if (window.ActiveXObject){ 
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
if (!xmlhttp){ 
	xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
} 

} 
  return xmlhttp; 

  
} 
var http = getHTTPObject(); // We create the HTTP Object 
</script> 
</head> 
<body> 
<select id="txtCustomerId" onchange="requestCustomerInfo()"> 
<option>Kies offertenummer</option> 
<?php 
mysql_connect(xxxxx,xxxx,xxxx); 
mysql_select_db(xxxxx); 
$query="select offerte from offertenummers order by offerte desc"; 
$result=mysql_query($query); 
while(list($CustomerId)=mysql_fetch_row($result)) { 
	echo "<option value=\"".$CustomerId."\">".$CustomerId."</option>"; 
} 
?> 
</select> 
<div id="divCustomerInfo"></div> 
</body> 
</html>

zoek_offerte_order.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<html> 
<head> 
<?php 

//customer ID 
$sID = $_GET["id"]; 

//variable to hold customer info 
$sInfo = ""; 

//database information 
$sDBServer = "xxxxx"; 
$sDBName = "xxxx"; 
$sDBUsername = "xxxx"; 
$sDBPassword = "xxxx"; 

//create the SQL query string 
$sQuery = "Select o.offerte, o.klant_id, o.omschrijving, a.klantnaam
FROM
offertenummers AS o
INNER JOIN
adressen AS a
ON a.id = o.klant_id  
where offerte=".$sID; 
		  
//make the database connection 
$oLink = mysql_connect($sDBServer,$sDBUsername,$sDBPassword); 
@mysql_select_db($sDBName) or $sInfo = "Unable to open database"; 

if($sInfo == '') { 
	if($oResult = mysql_query($sQuery) and mysql_num_rows($oResult) > 0) { 
		$aValues = mysql_fetch_array($oResult,MYSQL_ASSOC); 
		$sInfo = $aValues['klantnaam']."<br />".$aValues['omschrijving']."<br />".					  
				 "<a href=\"mailto:".$aValues['E-mail']."\">".$aValues['E-mail']."</a>"; 
	} else { 
		$sInfo = "Offertenummer $sID bestaat niet."; 
	} 
} 

mysql_close($oLink); 

?> 



</head> 
<body> 
<div id="divInfoToReturn"> <?php echo $sInfo ?> </div> 
</body> 
</html>

I habe 2 questions,

 

1st: why can't I remove the line 

"<a href=\"mailto:".$aValues['E-mail']."\">".$aValues['E-mail']."</a>";

if I do an error comes up.

 

2nd: how do I implement the code for the pulldown menu of test.php is this code:

<td class="dr"><select name="offerte_id">
<?php
  $sql = "select `offerte`, `offerte` from `offertenummers` ORDER BY `offertenummers`.`offerte` DESC";
  $res = mysql_query($sql, $conn) or die(mysql_error());

  while ($lp_row = mysql_fetch_assoc($res)){
  $val = $lp_row["offerte"];
  $caption = $lp_row["offerte"];
  if ($row["offerte_id"] == $val) {$selstr = " selected"; } else {$selstr = ""; }
?><option value="<?php echo $val ?>"<?php echo $selstr ?>><?php echo $caption ?></option>
<?php } ?></select>
</td>

 

Please help me solve this.

Link to comment
https://forums.phpfreaks.com/topic/140386-how-to-implement-an-pulldown-menu/
Share on other sites

1st answer .. if you wanna delete, you cant delete the semicolon .. so you have to replace

$sInfo = $aValues['klantnaam']."<br />".$aValues['omschrijving']."<br />".                 
                "<a href=\"mailto:".$aValues['E-mail']."\">".$aValues['E-mail']."</a>";

with this

$sInfo = $aValues['klantnaam']."<br />".$aValues['omschrijving']."<br />";

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.