OK, I have a routine that uses ajax (which I barely understand) to get dynamically the name of a show and put in a dropdown box using the dates in a database. Now, once the user gets the year of the show and the name of the venue, then it needs to be submtted to another php script to get the images (those come later). So, how do I accomplish this with javascript/ajax?
the script is here
<?php
session_start();
include_once(getRootPath(). 'inc/db_connect_PDO2.php');
$db = get_db_connection();
$result = $db->prepare('SELECT DISTINCT(Show_Year) FROM Show_Pix ORDER BY Show_Year DESC');
$result->execute();
// returns the relative path from current folder to Web Site Root directory
function getRootPath() {
$current_path = pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME);
$current_host = pathinfo($_SERVER['REMOTE_ADDR'], PATHINFO_BASENAME);
$the_depth = substr_count( $current_path , '/');
// Set path to root for includes to access from anywhere
if($current_host == '127.0.0.1') $pathtoroot = str_repeat('../' , $the_depth-1);
else $pathtoroot = str_repeat ('../' , $the_depth);
return $pathtoroot;
}
?>
<html>
<head>
<title>Roshan's Ajax dropdown code</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
function getXMLHTTP() { //fuction to return the xml http object
var xmlhttp=false;
try{
xmlhttp=new XMLHttpRequest();
}
catch(e) {
try{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1){
xmlhttp=false;
}
}
}
return xmlhttp;
}
function getName(strURL) {
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('showName').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
</script>
</head>
<body>
<form method="post" action="PicCapEdit.php?showYear=<?=$_POST['showYear']?>&showName=<?$_POST['showName']?>" name="form1">
<div width="60%" border="0" cellspacing="0" cellpadding="0">
<div style="clear:both;">
<div width="150" style="float:left;">Show Year </div>
<div width="150" style="float:left" ><select name="showYear" onChange="getName('findname.php?showName='+this.value)">
<option value="">Select Show Year</option>
<? while ($row = $result->fetch(PDO::FETCH_ASSOC)){ ?>
<option value=<?=$row['Show_Year'] ?>><?=$row['Show_Year'] ?></option>
<? } ?>
</select></div>
</div>
<div style="clear: both;">
<div width="150" style="float:left;">Show Name </div>
<div style="float:left;"><div id="showName" style="float:left;"><select name="showName">
<option>Select Show Name</option>
</select></div></div>
</div>
<div>
<div> </div>
<div> </div>
</div>
<div>
<div> </div>
<div> </div>
</div>
</div>
<input type="Submit" name="Form1_Submit" value="Submit">
</form>
</body>
</html>