Use the JS bulk check feature to change status status values in the database (batch display) _javascript tips

Source: Internet
Author: User

When we develop projects, we often use the bulk display function to dynamically modify the value of the database in the background management. The following is to modify the status state value of the database to achieve a bulk display function. The bulk check function refers to JS for implementation.

Front-End HTML code:

<table class= "MLT" style= "border:1px solid red;" > <thead> <tr> <if condition= "$type eq ' pg '" > <th colspan= "9" style= "TEXT-ALIGN:LEFT; Padding-left:20px;background-color: #e5e4e4; color: #c10e23; > Physical Products </th> <else/> <th colspan= "8" style= "text-align:left;padding-left:20px;background-color:# E5e4e4;color: #c10e23; " > Virtual Goods </th> </if> <th style= "Background-color: #e5e4e4;" > <a href= "{: U (' Mall/addmall ', Array (' type ' => $type)}" style= "color: #c10e23; text-decoration:none;" >+ New Products </a></th> </tr> <tr> <th style= "Background-color: #f7f7f7; width:8%;text-align: Center: class= "LF" > <input name= ' chkall ' type= ' checkbox ' id= ' chkall ' onclick= ' Checkall (this, ' id[] ') "value="
CheckBox '/>  </th> <th style= ' background-color: #f7f7f7 width:8%; "class=" LF "> Product number </th> <th style= "Background-color: #f7f7f7; width:13%;" class= "LF" > name </th> <th style= "background-color:# F7f7f7;width: 18% "class=" lf "> title </th> <if condition=" $type eq ' pg ' "> <th style=" background-color: #f7f7f7; : 8 class= "LF" > Brand </th> </if> <th style= "Background-color: #f7f7f7 width:8%;" class= "LF" > Group </th> <th style= "Background-color: #f7f7f7; width:5%;" class= "lf" > Sort </th> <th style= " Background-color: #f7f7f7 width:5%; "class=" lf "> Status </th> <th style=" Background-color: #f7f7f7; width:10%; " > Icon </th> <th style= "Background-color: #f7f7f7; text-align:center;" class= "LF" > Operation </th> </tr > </thead> <tbody> <volist name= "list" id= "Vo" > <tr> <td class= "lf" style= "text-align: Center; " > <input name= ' id[] ' type= ' checkbox ' value= ' {$vo. ID} ' onclick= ' Checkitem (this, ' Chkall ') "> </td> <td class= "LF" >{$vo [' Code ']}</td> <td class= ' lf ' >{$vo [' name ']}</td> <td] ' lf ' class= $vo [' Title ']}</td> <if condition= "$type eq ' pg '" > &LT;TD class= "LF" >{$vo [' Brand ']}</td> </if> <td class= "LF" >{$vo [' Ggroup ']}</td> <td "LF" class= $vo [' >{']}
</td> <td class= "LF" ><if condition= "$vo [' status '] eq 1" > Show <else/> not show </if></td> <td></td> <td class= "lf" style= "text-align: Center; " > <a href= "{: U (' Mall/nextlevel ', Array (' PID ' => $vo [' ID '])} ' class= ' CZ ' style= ' Text-decoration:none;" > Edit Sub-info </a> <a href= "{: U (' Mall/updatemall ', array (' ID ' => $vo [' ID '])}" class= ' CZ ' style= " text-decoration:none;margin:0 7px; " > Edit </a> <a href= "{$Think. config.web_url}/shop/goodsdetails.html?pid={$vo [' id ']}&type={$vo [' type ']
]} "class= ' CZ ' style=" Text-decoration:none "target=" _blank "> View </a> </td> </tr> </volist> <tr height= "> <td colspan=" style= "text-align:left;padding-left:40px" > <input type= "button" id= "Btn_show" value= "Batch display" class= "Btn_normal" style= "width:100px;margin-left:20px; " > </td> </tr> </tbody> </table> <div>{$page}</div>

JS code to use AJAX to submit code to the background Goodsshow () method:

<script type= "Text/javascript" >
var ids = [];///convert the resulting is into an array form of
$ (' #btn_show '). Click (function () {
Btncheck (' show ');
data = {
"IDs": IDs
};
$.ajax ({
type: "POST",
URL: "{: U (' Mall/goodsshow ')}",
Data:data,
//datatype: "JSON"
, Success:function (msg) {if
(msg = 00) {//If msg=00 modifies success
alert ("Batch show success");
window.location.href= '/index.php/admin/mall/malllist '; Automatically refresh}else{alert after the modification is complete
("Bulk display failed, edit again")
}
},
error:function () {
alert ("Bulk edit failed, Please edit it Again "); Error Prompt}}); 
function Btncheck (info) { 
var obj = $ ("input[name= ' id[] ']:checked"). each (function () {//Get each value of the selected ID and this value is an array
Ids.push ($ (this). Val ());
if (ids = False) { 
alert ("Please select the item to +info+");
return false;
} else {return
IDs; 
}
}
</script>

Background goodsshow () method:

Public Function Goodsshow () {
$goods =m (' shop_goods_info ');//Instantiate the data table to use
$data = I ();// Gets the ID value of the foreground page (this value is an array)
//var_dump (I (' IDs '));d ie ();//Print
$id =implode (', ', I (' IDs ')); The resulting array is split with the Implode method 
//var_dump (I (' id '));d ie ()///Print view
$order = $goods->where ("ID in ($id)")-> SetField (' status ', ' 1 '); Matches the ID value in the database with the resulting $id value, and sets the Status field value under ID to 1.
if ($order >=1) {//If ... else 
... $remark = "a";
else{
$remark = "a";
}
echo $remark;
}

The above is a small set to introduce the use of JS Bulk check function to achieve change in the status of the database state value (batch display), I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.