Pull-down linkage related issues

Source: Internet
Author: User
Pull-down linkage problem
Provincial and municipal linkage, the contents of the provinces and cities are taken out of the database,
Now is the choice of the province, the corresponding city came out, the province back to the original value, the selected value is not saved, because the screen has been refreshed.
Is there any way to save the province, or not to refresh the screen?

Here's some code



Province





City





Initially, the binding province
Public Function Action ()
{

$RETARR =array ();
Province to obtain
$RETARR = $this->qamodel->getprovince ();

if (count ($RETARR) >0)
{
foreach ($retArr as $key = $i)
{
$provinceList [$i ["Province_key"]] = $i ["Province_name"];
}
}
Get したデータを Setup
$this->_smarty->assign ("Provincelist", $provinceList);

お尻 asked Kei わせ picture to show able this step display screen submit.html
$this->_smarty->render ($this->_language. " /submit ");
}

Linkage, binding City
Public Function cityaction ()
{
$province _key= $this->_context->query ("Province_key", "" ");

$this->log->info ($province _key);


$RETARR =array ();
Province to obtain
$RETARR = $this->qamodel->getcity ($province _key);

if (count ($RETARR) >0)
{
foreach ($retArr as $key = $i)
{
$cityLis [$i ["City_key"]] = $i ["City_name"];
}
}

Get したデータを Setup
$this->_smarty->assign ("CityList", $cityLis);

お尻 asked Kei わせ picture to show able this step back to the beginning, so that the province will be re-bound
$this->action ();
}


------Solution--------------------
What kind of Web site are you in this mess of Japanese? In Japan? It is used in prefectures and municipalities in Japan.
It is recommended to do it with Ajax. This speed is fast and does not need to be refreshed every time.

Prefectural Prefectures {html_options options= $res. M_states selected= $res. mst_state_id------Solution--------------------Default: "}
Municipal html_options options= $res. m_city selected= $res. mst_city_id------Solution--------------------Default: "}

function Linkage (obj,id) {
var param = {};
param.mst_state_id = obj;
$.ajax ({
Type: "POST"
, url: "PHP"
, Data: $.param (param)
, Datetype: "xml"
, Success:function (XML) {
var selects = $ ("select[id=" +id+ "]");
$ (selects) [0].length=0;
$ (selects) [0].options[0]=new Option ("municipality", "0");
$ ("category", XML). each (function () {
var id = $ ("id", this). Text ();
var name = $ ("name", this). Text ();
$ (selects) [0].options.add (New Option (name, id));
});
}
});
}

URL: "PHP" Here is the PHP note path that accepts the IDs of all prefectures
This PHP final output

$str = "";
  • 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.