Jump to content

ajax related question(how to access second combo box values)


zohab

Recommended Posts

hi all

 

i have used following code in my project.There are 2 combo box first one dependent

on other now the problem is i want to perform operation on second combo box

i am not able to get value from second  combo box.

e.g in select box we have values in <option value=""></option>

i need option value or other to perform operation

 

 

dynamicdropdown.php

<?

include("mysqlconnect.php"); 

 

$db='universus';

mysql_select_db($db);

 

?>

 

 

 

 

 

<html>

<head>

<script src="selectcustomer.js"></script>

</head>

 

<body>

 

<form>

Select a Project Name:

<? $sql_sel="select * from prjmaster";

$res=mysql_query($sql_sel);

?>

<select name="prjname" onchange="showCustomer(this.value)">

<?

while($row1=mysql_fetch_array($res)){

 

  echo "<option " .$select. " value='".$row1['prjID']."'>".$row1['prjName']."</option>";

}

echo "</select>";

?>

</form>

 

<p>

<div id="txtHint">Task info will be listed here.</div>

</p>

 

</body>

</html>

 

<script language="javascript">

var xmlHttp

 

function showCustomer(str)

{

xmlHttp=GetXmlHttpObject();

if (xmlHttp==null)

  {

  alert ("Your browser does not support AJAX!");

  return;

  }

var url="gettask.php";

url=url+"?q="+str;

url=url+"&sid="+Math.random();

xmlHttp.onreadystatechange=stateChanged;

xmlHttp.open("GET",url,true);

xmlHttp.send(null);

}

 

function stateChanged()

{

if (xmlHttp.readyState==4)

{

document.getElementById("txtHint").innerHTML=xmlHttp.responseText;

 

//alert(document.getElementById("txtHint").innerHTML);

 

}

}

 

function GetXmlHttpObject()

{

var xmlHttp=null;

try

  {

  // Firefox, Opera 8.0+, Safari

  xmlHttp=new XMLHttpRequest();

  }

catch (e)

  {

  // Internet Explorer

  try

    {

    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

    }

  catch (e)

    {

    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

    }

  }

return xmlHttp;

}

</script>

 

gettask.php

<?

include("mysqlconnect.php"); 

 

$db='universus';

mysql_select_db($db);

 

$id=$_REQUEST['q'];

//echo "$id";

$sql_task="select * from prjtaskdetail where prjID='".$id."'"; 

$query2=mysql_query($sql_task);

 

echo "<select name='prjtask'>";

 

while($row2 = mysql_fetch_array($query2)){

echo "<option value='".$row2['taskID']."'>".$row2['Description']."</option>";

}

echo "</select>";

 

 

?>

 

 

 

 

 

 

 

need help.

 

thanks in advance

 

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.