Jump to content

dynamic selection list


rameshfaj

Recommended Posts

I need to have two selection fields whose value are populated from the database.

When the user selects a particular value in field A then the user should only be able to select the values in the second list that change with the value of the first list.

Ex:

List A,if has values like number,characters,operators, then if the user selects the value number then the field B should contain values 0,1,-9, when the value of the first field is character, the second field should be populated with the values like A,B---, similarly for the operator values in the first field,the option values in the second field should be +,_,-,*,% etc.

How can I achieve this?Plz help me.

Link to comment
https://forums.phpfreaks.com/topic/39760-dynamic-selection-list/
Share on other sites

hi,

list means-dropdown menu or some thing else.

i will send u a sample code.

 

index.php

if name of the client is selected then corresponding mail id should displayed....

<tr>

<td >ClientName</td>

<td ><? $sql_sel="select * from tb_client";

$db->query($sql_sel)or die($db->error());

 

echo "<select  name='client_id' onChange='info1()'>";

/*echo "<option>Select Client Name</option>";*/

while($row5=$db->fetchArray())

 

echo "<option value=\"$row5[mailid]\">$row5[clientname]</option>";

 

echo "</select>";

 

?></td>

</tr>

<tr>

<td >ClientMail ID</td>

<td >

<!--<input name="email3"  id="my_div" size="30">-->

  <div id="my_div">

Select Client Name:

</div>

</td>

</tr>

 

Script.js---this page contain ajax coding

// JavaScript Document

//Create Microsoft.XMLHTTP Object

function makeObject(){

var x;

var browser = navigator.appName;

//detect the client browser

if(browser == "Microsoft Internet Explorer"){

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

}else{

x = new XMLHttpRequest();

}

return x;

}

 

//call the function makeObject()

var request = makeObject();

 

 

//function send request

function info1(){

//alert("hh");

var val = document.form.client_id.options[document.form.client_id.selectedIndex].value;

 

//alert(val);

request.open('get', 'test.php?id=' + val);

request.onreadystatechange = parseInfo;

request.send('');

}

//function send data

function parseInfo(){

if(request.readyState == 1){

document.getElementById('my_div').innerHTML = 'Loading...';

}

if(request.readyState == 4){

var answer = request.responseText;

document.getElementById('my_div').innerHTML = answer;

}

}

 

test.php--the value is displayed in the div area of index.php

 

<?if( $_GET['id'] != "" )

{

//echo "hhh";

echo $id=$_GET['id'];

}

?>

 

 

 

 

  • 2 months later...

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.