ajax+juqery+php Two select option Control pass Value

Source: Internet
Author: User

<?php

for ($i =0; $i < $num; $i + +)

{

$n = $i +1;


echo "<tr><td align=center id=th2> $n";


$idd = ' stt_ '. $i;

echo "<input type=text name=kname[$i] value= ' $kname [$i] ' placeholder= ' units retrieved ' class= ' STT ' id=\ ' $idd \ ' ></input& gt; ";

$add = ' add_ '. $i;

echo "<td><center><input type=text name=acc_name1[$i] value= ' $ACC _name1[$i] ' size=30></td>

<td><center><input type=text name=amt1[$i] value= ' $amt 1[$i] ' class= ' Add ' id=\ ' $add \ ' size=10></ Td> ";

$id 1= ' user_ '. " $i ";

echo "<td ><select name=user[$i] id=\" $id 1\ ">

</select> ";

echo "</tr>";

}


echo "</table>";


?>



<script type= "Text/javascript" >

$ (". Sty"). Change (function () {

var inno = This.value;

var next = This.id.split ('_') [1];

$.ajax ({

Type: ' Post ',

URL: "find_user.php?" + Math.Round (math.random () *100),

data:{"Inno": Inno},

ContentType: "application/x-www-form-urlencoded; Charset=utf-8 ",

Success:function (data) {

data = eval (' (' +data+ ') ');

$ ("#user_" +next). empty ();

for (i=0;i<data.length;i++) {

$ ("<option></option>"). Val (Data[i].empl). Text (data[i].empl+ '-' +data[i].name+ '-' +data[i].dep). AppendTo ($ ("#user_" +next));

}

},

Error:function () {alert ("error");}

});

});

</script>



find_user.php


<?php

Require_once ('/php/public/id.inc ');

Require_once ('/php/public/opendb.inc ');

Require ("/php/public/power.inc");

Header ("Content-type:text/html;charset=utf-8");


function Field_ora ($sql) {

Global $dbhUTF;

$stmt = $dbhUTF->prepare ("$sql");

if ($stmt->execute ()) {

return $stmt->fetch ();

}

}


$inno =$_post[inno];


$sql _exx= "Select Depart_no from Acc_gl_depart where acc_depart_no= ' $inno '";

$sql _exp= $dbhUTF->prepare ($sql _exx);

$sql _exp->execute ();

List ($dept _clear) = $sql _exp->fetch ();

if ($dept _clear== ' 516000 ') {

$sql 4= "select Employee_no,name,get_depart (employee_no)

From employee

where depart_no = ' $dept _clear ' and lead_code= ' 20 ' ";

$sql 4_exe= $dbhUTF->prepare ($sql 4);

$sql 4_exe->execute ();

$i = 0;

while (list ($employee _no, $name, $dept _no) = $sql 4_exe->fetch ()) {

#echo "$employee _no-$name-$dept _no";

$a [$i]=array (' Empl ' + $employee _no, ' name ' = = $name, ' dep ' = $dept _no);

$i + +;

}

}

ElseIf ($dept _clear== ' 300001 ' or $dept _clear== ' 300002 ' or $dept _clear== ' 300003 ' or $dept _clear== ' 300004 ') {

$DEP _no3=substr ($dept _clear,0,2);


$sql 4= "Select Employee_no,name (Employee_no), Get_depart (Employee_no)

From Psm_double_work

where Depart_no like ' $dep _no3% ' ";

$sql 4_exe= $dbhUTF->prepare ($sql 4);

$sql 4_exe->execute ();

$i = 0;

while (list ($employee _no, $name, $dept _no) = $sql 4_exe->fetch ()) {

#echo "$employee _no-$name-$dept _no";

$a [$i]=array (' Empl ' + $employee _no, ' name ' = = $name, ' dep ' = $dept _no);

$i + +;

}

}

ELSE if ($dept _clear== ' J11040 ') {

$sql 4= "select Employee_no,name,get_depart (employee_no)

From employee

where depart_no = ' $dept _clear ' and lead_code= ' 50 ' ";

$sql 4_exe= $dbhUTF->prepare ($sql 4);

$sql 4_exe->execute ();

$i = 0;

while (list ($employee _no, $name, $dept _no) = $sql 4_exe->fetch ()) {

#echo "$employee _no-$name-$dept _no";

$a [$i]=array (' Empl ' + $employee _no, ' name ' = = $name, ' dep ' = $dept _no);

$i + +;

}

}

else{

$DEP _no1=substr ($dept _clear,0,5). " 0 ";

List ($sqlcnt) =field_ora ("SELECT count (*) from psm_double_work where depart_no= ' $dep _no1 '");

if ($sqlcnt >0)

{

$sql 4= "Select Employee_no,name (Employee_no), Get_depart (Employee_no)

From Psm_double_work

where depart_no= ' $dep _no1 ' ORDER by lead_code DESC ";

$sql 4_exe= $dbhUTF->prepare ($sql 4);

$sql 4_exe->execute ();

$i = 0;

while (list ($employee _no, $name, $dept _no) = $sql 4_exe->fetch ()) {

# echo "$employee _no-$name-$dept _no";

$a [$i]=array (' Empl ' + $employee _no, ' name ' = = $name, ' dep ' = $dept _no);

$i + +;

}

}

Else

{

$DEP _no2=substr ($dept _clear,0,3). " 000 ";

List ($sqlcnt 2) =field_ora ("SELECT count (*) from psm_double_work where depart_no= ' $dep _no2 '");

if ($sqlcnt 2>0)

{

$sql 4= "Select Employee_no,name (Employee_no), Get_depart (Employee_no)

From Psm_double_work

where depart_no= ' $dep _no2 ' ";

$sql 4_exe= $dbhUTF->prepare ($sql 4);

$sql 4_exe->execute ();

$i = 0;

while (list ($employee _no, $name, $dept _no) = $sql 4_exe->fetch ()) {

#echo "$employee _no-$name-$dept _no";

$a [$i]=array (' Empl ' + $employee _no, ' name ' = = $name, ' dep ' = $dept _no);

$i + +;

}

}

Else

{

$DEP _no3=substr ($dept _clear,0,2). " 0000 ";


$sql 4= "Select Employee_no,name (Employee_no), Get_depart (Employee_no)

From Psm_double_work

where depart_no= ' $dep _no3 ' ";

$sql 4_exe= $dbhUTF->prepare ($sql 4);

$sql 4_exe->execute ();

$i = 0;

while (list ($employee _no, $name, $dept _no) = $sql 4_exe->fetch ()) {

# echo "$employee _no-$name-$dept _no";

$a [$i]=array (' Empl ' + $employee _no, ' name ' = = $name, ' dep ' = $dept _no);

$i + +;

}

List ($employee _no, $name, $dept _no) = $sql 4_exe->fetch ();

if (! $employee _no) {


$sql 5= "Select Employee_no,name (Employee_no), Get_depart (Employee_no)

From employee

where depart_no= ' $dept _clear ' ";

$sql 5_exe= $dbhUTF->prepare ($sql 5);

$sql 5_exe->execute ();

$i = 0;

while (list ($employee _no, $name, $dept _no) = $sql 5_exe->fetch ()) {

#echo "$employee _no-$name-$dept _no";

$a [$i]=array (' Empl ' + $employee _no, ' name ' = = $name, ' dep ' = $dept _no);

$i + +;

}


}

}


}


}

echo Json_encode ($a);

?>

ajax+juqery+php Two select option Control pass Value

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.