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
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'];

}

?>

 

 

 

 

Link to comment
Share on other sites

  • 2 months later...

i have same problem i try to use javascript but it refreshing the page, i have 3 table (country, state, city) i want to display only respective state shown when a country is selected. and same for state and city).  i am using php mysql

 

hope to get reply soon

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.