i want make 3 dependents drop down list, each drop down dependent previous drop down, when select item first drop down , data fetch database , add second drop down item. know how in normal php page using ajax, opencart uses mvc don't know how can selected value
basically, need 2 things:
(1) handling list changes
add event handler each list gets selected value when changes (the part know), detailed tutorial here in case needed it
just suggestion (for code optimization), instead of associating separate js function each list , repeating code, can write function once, pass id of changing list along id of depending list , use anywhere.
html should
<select id="list1" onchange="populatelist('list1', 'list2')"> ... </select> <select id="list2" onchange="populatelist('list2', 'list3')"> ... </select> <select id="list3"> ... </select> and js
function populatelist(listid, deplistid) { // value of changed list thorugh fetching elment id "listid" var listvalue = ... // values set in depending list through ajax var deplistvalues = ... // populate depending list (element id "deplistid") } (2) populating depending list
send value through ajax appropriate php function , values update depending list (the part asking for), ajax detailed tutorial here
open cart uses front controller design patter routing, url looks like:
bla bla bla.bla/index.php?route=x/y/z&other parameters, x = folder name contains set of class files, y = file name contains specific class, z = function called in class (if omitted, index() called)
so answer question is:
(step 1) use following url in ajax request:
index.php?route=common/home/populatelist
(step 2) open file <oc_root>/catalog/controller/common/home.php , find class controllercommonhome, add new function name populatelist , add logic there
(step 3) use database object, answered here
note: if @ admin side, there security token must present in links along route, use url:
index.php?route=common/home/populatelist&token=<?php echo $this->session->data['token'] ?> , manipulate file @ admin folder not catalog
p.s: whenever user changes selected value in list # i, should update options in list # + 1 , reset following lists list # + 2, list # + 3 ..., in case should reset third list when first list value changed
p.p.s: guide oc 1.5.x => here (it can used reference oc 2.x modifications)
Comments
Post a Comment