Selected refresh the page selected the selected value is not table (thinkphp from the controller assign value to JS)

Source: Internet
Author: User

Last night to resolve the Select Refresh page after the selected values remain unchanged, in order to let the seleted unchanged, there are two ways,

1, when submitting the form, set the property of the selected option to checked.

2. Take option value or index away, in fact, this commit takes the value directly, create an array, PHP uses Array_search () to find the value of the index of value, refresh and then pass the value of index, Use jquery. Select the value of the index as checked when the page has finished loading.

I chose the second method. Code as follows, the pro-test is effective;

Foreground code (bold for critical code)

<! DOCTYPE html>
<meta charset= "Utf-8" >
<title> Background Management </title>
<link rel= "stylesheet" href= "__css__/main.css" >
<link rel= "stylesheet" href= "__css__/validate.css" >
<script type= "Text/javascript" src= "__js__/jquery.js" ></script>
<script type= "Text/javascript" src= "__js__/common.js" ></script>
<script type= "Text/javascript" src= "__js__/validate.js" ></script>
{$code}
<body>
<div class= "Container" >
<form name= "Form1" action= "__controller__/info" >

<select id= "static" Name= "Rank" onchange= "Document.form1.submit ()" >
<option value= "id" > View by registration time </option>
<option value= "Sign" > by check-in times </option>
<option value= "Score" > View by number of points </option>
</select>

<table cellpadding= "3" cellspacing= "1" align= "center" class= "box" >
<tr>
<th width= "50px" > Avatar </th>
<th width= "" > Account </th>
<th> name </th>
<th width= "" > Gender </th>
<th width= "" > Age </th>
<th width= "" > Phone </th>
<th width= "" > City </th>
<th width= "" > Shop </th>
<th width= "" > Points </th>
<th width= "" > Sign-in times </th>
</tr>
<volist name= ' list ' id= ' Vo ' >
&LT;TR class= "List" >
&LT;TD align= "center" ></td>
&LT;TD align= "center" >{$vo .account}</td>
&LT;TD align= "center" >{$vo .name}</td>
&LT;TD align= "center" >{$vo .gender}</td>
&LT;TD align= "center" >{$vo .age}</td>
&LT;TD align= "center" >{$vo .phone}</td>
&LT;TD align= "center" >{$vo .city}</td>
&LT;TD align= "center" >{$vo .shop}</td>
&LT;TD align= "center" >{$vo .score}</td>
&LT;TD align= "center" >{$vo .sign}</td>
</tr>
</volist>
</table>
<div> {$PAP}</div>
</div>
</body>
Because I use the people thinkphp framework, so design a problem is from the controller to wear variables to the foreground JS code problem, if directly in the controller $this->assign (' Code ', $code);

It is not useful to call {$code} in the foreground JS, so it is necessary to assign the <script>.....<script/> intermediate code to the variable directly in the background.

The controller handles the code as follows:

Background code

Public Function info ()
{
$shop =m (' Stu ');
$count = $shop->count ();//query satisfies the required total number of records
$Page = new \think\page ($count, 6);//Instantiate the total number of incoming records for the paging class and the number of records displayed per page (2)
$Page->setconfig (' prev ', ' prev ');
$Page->setconfig (' Next ', ' next page ');
$Page->setconfig (' Last ', ' End ');
$Page->setconfig (' first ', ' home ');
$show = $Page->show ();//pagination display output
if (I (' rank '))Drop-down list select how to view
{
if (I (' rank ') = = ' id ')
{
$list = $shop->limit ($Page->firstrow. ', '. $Page->listrows)->select ();
}
else{
$list = $shop->limit ($Page->firstrow. ', '. $Page->listrows)->order (I (' rank '). ' desc ')->select ();
}

}
Else
{
$list = $shop->limit ($Page->firstrow. ', '. $Page->listrows)->select ();
}
for ($i =0; $i < $count; $i + +)//To take out paging data, since the previous check-in count is 1
{
$list [$i] [' sign ']= $list [$i] [' sign ']+1;
}
$a =array (' id ', ' sign ', ' score ');
$index =array_search (I (' rank '), $a);
$code = ' <script type= ' text/javascript ' >
$ (document). Ready (function () {
var selectedindex = '. $index. ';
if (selectedindex! = null) {
document.getElementById ("Static"). SelectedIndex = SelectedIndex;
             } ;
        })  
</script> ';
$this->assign (' Code ', $code);
$this->assign (' list ', $list);//Assign Columns to list
$this->assign (' pap ', $show);//Assignment Paging output
$this->display (); Output template
}

Selected refresh the page selected the selected value is not table (thinkphp from the controller assign value to JS)

Related Article

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.