1

Main Drop-down :

<select name="sometest">
  <option value="1"> A </option>
  <option value="2"> B </option>
  <option value="3"> C </option>
  <option value="4"> D </option>
  <option value="5"> E </option>
</select>

Now here When value 1 , 2, 3 , 4 is on-change it should get its details from table_1 and when Value 5 is on-change then its details come from another table_2 with field( name , size , title) .

Kindly note both table_1 and table_2 have same coloumn field name.

now after onchange of resp. value i get another drop-down listing with resp. table query.

Suppose when i on-change for 1 or 2 or 3 or 4 value , then it query table_1 with field name, size, title and list it under resp drop-down sections.

Drop-down list : on-change value for 1,2,3,4 from table_1

Here : coloumn "name" all value is listed under name , coloumn "size" all value is listed under size and coloumn "title" all value is listed under title from table_1

<select name="name">
  <option value="n1"> Apple </option>
  <option value="n2"> Boy </option>
  <option value="n3"> Cat </option>
</select>

<select name="size">
  <option value="12"> 0-1 </option>
  <option value="21"> 1-1 </option>
</select>


<select name="title">
  <option value="1"> whatever </option>
  <option value="2"> same whatever </option>
</select>

similarly when Value 5 is select from Main Drop-down , then it query all column field from table_2 and list it under resp. drop-down

4
  • r u using ajax for get result? Commented Jan 13, 2014 at 7:22
  • i am newbie , so no idea about it .. hence asking for help :( Commented Jan 13, 2014 at 7:23
  • Did you try any code ? Commented Jan 13, 2014 at 7:27
  • @ Mahmood , as said i am newbie in jquery , ajax .. but yes i tried my hand on studying jquery and ajax , and after some research i got to know that Onchange of jquery with ajax in loop may help me on this .. but confuse to start from where , as from Main dropdown i have to query 2 table as per its value Commented Jan 13, 2014 at 7:30

1 Answer 1

1

user ajax onchange select box pass the value of select

HTML

 <select name="sometest" onchange="javascript:call_ajax_fun(this.value);">
      <option value="1"> A </option>
      <option value="2"> B </option>
      <option value="3"> C </option>
      <option value="4"> D </option>
      <option value="5"> E </option>
    </select>

JS Ajax Function

function call_ajax_fun(str)
{

    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange=function()
    {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {

            var result = xmlhttp.responseText;
            if(xmlhttp.responseText!='')
            {
                document.getElementById('your_result_div_id').innerHTML =result ;
                            // put your result in your div 
            }   
        }
    }



    var url="get_result.php?pas_val="str;

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

    xmlhttp.send();
}

and your get result file will be as follows

get_result.php

<?php
if(isset($_REQUEST['pas_val']))
{
   $pas_val = $_REQUEST['pas_val'];
   if($pas_val<5)
   {
     $tbl = "table_1";
   }
   else
  {
     $tbl = "table_2";
  }


// your table is in $tbl variable
//   your your table here in your code


}
else
{
  exit;
}
?>
Sign up to request clarification or add additional context in comments.

2 Comments

@ Satish thanks for reply , but what about listing of my other dropdowns values from resp. tables as per column fields
@user2906577 use $pas_val in if-else on get_result.php and define your table as i edited the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.