Js+jquery is the linkage

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

This work needs to be linked to write a tree, then wrote a scalable infinite linkage drop-down option

Code written compared messy first mark   free again finishing

Fuck!

Company QQ can't just cut a figure!

To put the database

Idcategory_name PID father idorders sort 122223331012222211 11124444411052222 11622221111333 2013555555120 classification

Page code with the SMARTY

<div id="select" >
    <select name="category_1" id="category_1" onChange="change('category_1');">
        <option>Please select a category</option>
        <!-- {foreach from=$galleryCategory item=category} -->
            <option value="{$category.id}">{$category.category_name}</option>
        <!-- {/foreach} -->    
    </select>
</div>

$galleryCategory to the data of the PHP code for

$sql = " select * from yl_gallery_category where pid = 0";
$galleryCategory = $db->query($sql);
$smarty->assign("galleryCategory",$galleryCategory);

  To resign colleagues project to wipe my ass with     original code is easier to understand.

Then is the key source of the JS function change (VAL) {

var str = val; //Select id
    var num; //The current series

    var id; // Classification of ID
    num = str.substr(9,10);
    //alert(num);
    var nownum = parseInt(num)+1; // Converting a string to a number
    id = $("#"+str+"").val();
    var r = /^[1-9]+[0-9]*]*$/; //A positive integer
    if (!r.test(id)) {
        //Empty out of options
        $("select").each(function(index){
            if(index+1 > num) {
                $(this).remove();
            }
        })
        
        return false;
    }
    var url = 'gallery.php?act=category&pid='+id;
    $.ajax({
        type: "POST",
        cache: false,
        url: url,
        datatype : 'json',
        timeout : 3000,
        success: function(result){
            if ( result != 0) {    
                var html = "<select name=category_"+nownum+"     id=category_"+nownum+"  onChange=change('category_"+nownum+"'); >";
                html + = "<option> please select </option>";
                var datas = eval(result);
                $.each(datas, function(i,val){      
                    html += "<option value='"+val.id+"' >"+val.category_name+"</option>";
                });   
                html += "</select>";
                
                //Empty out of options
                $("select").each(function(index){
                    if(index+1 > num) {
                        $(this).remove();
                    }
                })
                
                $("#select").append(html);
            } else {
          //Empty out of options
                $("select").each(function(index){
                    if(index+1 > num) {
                        $(this).remove();
                    }
                })
       }
                
        },
        error: false
    });
    
}

AJAX data of PHP code 

$sql = " select * from yl_gallery_category where pid = " .$pid;
	$res = $db->query($sql);
	if (empty($res)) {
		$res = 0;
	}
	echo json_encode($res);

 OK be accomplished!





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Ellie at October 24, 2013 - 1:04 AM