Thứ Sáu, 27 tháng 12, 2024

ERROR sql_mode, Select hai cấp javascript changeDynaList


 **** Template

<form name="adminForm">

<script>

function changeDynaList( listname, source, key, orig_key, orig_val ) {

var list = eval( 'document.adminForm.' + listname );

// empty the list

for (i in list.options.length) {

list.options[i] = null;

}

i = 0;

for (x in source) {

if (source[x][0] == key) {

opt = new Option();

opt.value = source[x][1];

opt.text = source[x][2];


if ((orig_key == key && orig_val == opt.value) || i == 0) {

opt.selected = true;

}

list.options[i++] = opt;

}

}

list.length = i;

}

var sinhvienlop = new Array;

// sinhvienlop[$key] = new Array( 'mid','catid','title');

sinhvienlop[0] = new Array( '0','0','Chon SV' );

sinhvienlop[1] = new Array( '1','10','SV1' );

sinhvienlop[2] = new Array( '1','11','SV1-1' );

sinhvienlop[3] = new Array( '2','2','SV2' );

sinhvienlop[4] = new Array( '3','3','SV3' );

</script>


<select class="form-control admin-width-200" style="float:left;margin-right:10px;" name="lop" id="lop" size="1" onchange="changeDynaList( 'sinhvien', sinhvienlop, document.adminForm.lop.options[document.adminForm.lop.selectedIndex].value, 0, 0);">

    <option value="0" selected="selected">- Chọn lớp -</option>

    <option value="1" >Lop 1</option>

    <option value="2" >Lop 2</option>

    <option value="3" >Lop 3</option>

</select>

<select class="form-control admin-width-200" name="sinhvien" id="sinhvien" size="1">

        <option value="0" >Chon SV</option>

</select>

</form>


 **** Code đang sử dụng

<form enctype="multipart/form-data" action="link đến trang" method="post" name="adminForm">

<script language="javascript" type="text/javascript">

var sectioncategories = new Array;

sectioncategories[0] = new Array( '-1','-1','Select Category' );

// sectioncategories[1] = new Array('0','0','Uncategorized' );

<?php

$sql="SELECT b.mid as mid, b.custom_title  as title FROM modules b ";

  $result = $db->sql_query($sql);

$i=2;

while ($row = $db->sql_fetchrow($result)) {

      $midcha = $row['mid'];

    echo "sectioncategories[$i] = new Array('$midcha','0','Chủ đề chính','0') \n\n";

    $i++;

    $sqls="SELECT  a.*, b.title FROM stories_cat a,stories_cat_lang b  where a.catid=b.catid 

            and b.lang_id='$langid' and  a.mid ='$midcha' order by a.parentid,a.weight";

    $results = $db->sql_query($sqls);

    while ($rows = $db->sql_fetchrow($results)){   

$mid    = $rows['mid'];
$catid = $rows['catid'];
$title = $rows['title'];
$pid = $rows['parentid'];

echo "sectioncategories[$i] = new Array( '$mid','$catid','$title','$pid' ) \n\n";

$i++;

      }

?>
</script>

<select class="form-control admin-width-200" style="float:left;margin-right:10px;" name="sectionid" id="sectionid" class="inputbox" size="1" onchange="changeDynaList('catid', sectioncategories, document.adminForm.sectionid.options[document.adminForm.sectionid.selectedIndex].value, 0, 0);">

<option value="-1" >- Modules -</option>

<!-- <option value="0"  selected="selected">Uncategorized</option> -->

<?php

$sql3="SELECT  DISTINCT b.mid as mid, b.custom_title as title FROM stories_cat a right JOIN modules b ON a.mid=b.mid WHERE b.active =1 and b.mid !=368 and b.mid !=369 order by a.weight asc";

$result3 = $db->sql_query($sql3);

while ($row3 = $db->sql_fetchrow($result3)) {

$mid3   = $row3["mid"];
$title3   = $row3["title"];

  echo'<option value="'.$mid3.'">'.$title3.'</option>';

}

?>

</select>


<select class="form-control admin-width-200" name="catid" id="catid" class="inputbox" size="1">

<option value="-1" >Select Category</option>

</select>

</form>


<script>

function changeDynaList( listname, source, key, orig_key, orig_val ) {

var list = eval( 'document.adminForm.' + listname );

// empty the list

for (i in list.options.length) {

list.options[i] = null;

}

i = 0;

for (x in source) {

if (source[x][0] == key)

{

opt = new Option();

if(source[x][3]==0)

{

opt.value = source[x][1];

opt.text = source[x][2];

}

else

{

y=source[x][3];

for(k in source)

{

if(source[k][1]==y)

{

z=source[k][2];

break;

}

}

opt.value = source[x][1];

opt.text = z+' > '+source[x][2];

}

if ((orig_key == key && orig_val == opt.value) || i == 0) {

opt.selected = true;

}

list.options[i++] = opt;

}

}

list.length = i;

}

</script>

Không có nhận xét nào:

Đăng nhận xét