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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.