Welcome Guest, Not a member yet? Register   Sign In
Ajax select and select (dropbox)
#1

[eluser]nubianxp[/eluser]
Can anyone point me to some sample CI implementation where
an ajaxed select dropdown option opens up another select dropdown
depending on the first one?

Thanks!
#2

[eluser]TheFuzzy0ne[/eluser]
Unlikely, as the Ajax wouldn't have anything to do with CodeIgniter as such.

You could also implement it in pure JavaScript (no Ajax required), thus making everything faster.
#3

[eluser]nubianxp[/eluser]
[quote author="TheFuzzy0ne" date="1239816662"]Unlikely, as the Ajax wouldn't have anything to do with CodeIgniter as such.

You could also implement it in pure JavaScript (no Ajax required), thus making everything faster.[/quote]

Thanks for the quick reply, it would be nice to do in javascript but the problem is that the selections are generated dynamically and pulled from the database depending on what the selection is.

The scenario is that I have search form with a list of Islands and then each island has its own region which in turn has its own areas and subareas and this in turn will generate the query.

Anyways, any pointers to places where this kind of thing got implemented using javascript?

Thanks.
#4

[eluser]SteveBluck[/eluser]
I would also be interested in something like this. I cant find anything on google.
#6

[eluser]nubianxp[/eluser]
[quote author="TheFuzzy0ne" date="1239818372"]http://www.dhtmlgoodies.com/scripts/ajax...elect.html
http://www.ajaxf1.com/tutorial/ajax-mast...elect.html
http://www.satya-weblog.com/2007/04/dyna...st-by.html[/quote]

Ok, will be reviewing this.
Thanks for taking the time man, appreciate it.
#7

[eluser]Berserk[/eluser]
Roadmap: select an option from Selection A -> call an ajax function with onchange event of Selection A -> display results from ajax function on Selection B

an example with xajax:

Controller
Code:
//Ajax function to get albums list by an artist
    function get_artist_albums($aId)
    {
        $objResponse = new xajaxResponse();        
        $sHtml = '';
        
        $aAlbums = $this->music->get_albums_by_artist($aId);
        foreach($aAlbums as $aAlbum)
        {
            $sHtml .= '<option value="'.$aAlbum->album_id.'">';
            $sHtml .=  $aAlbum->album_name;
            $sHtml .= '</option>';            
        }
        $sTxt = $sHtml;
        $objResponse->Assign('album','innerHTML',$sTxt);        
        return $objResponse;
    
    }

Views:

Code:
//Display Artists List
<select name="artist" id="artist" o_n_c_h_a_n_g_e="xajax_get_artist_albums(this.options[this.selectedIndex].value);">
            <option value="none">Choose One</option>
            &lt;?php foreach($artists as $artist): ?&gt;
            <option value="&lt;?=$artist->artist_id?&gt;">&lt;?=$artist->artist_name?&gt;</option>
            &lt;?php endforeach ?&gt;
            
</select>

//Display results when call get_artist_albums()
<select name="album" id="album">        

</select>

hope it'll help
#8

[eluser]nubianxp[/eluser]
Thanks berserk, I'm trying xajax out now, it's a bit confusing since I'm using the form helper with it, and there's the issue of the event handler.

BTW, on the onchange code, I noticed you used:
Code:
xajax_get_artist_albums(this.options[this.selectedIndex].value)
instead of:
Code:
xajax_get_artist_albums(this.value)
any particular reason? and is the "xajax_" prefix required?
#9

[eluser]Berserk[/eluser]
no, i used for a test.and "xajax_" is default prefix




Theme © iAndrew 2016 - Forum software by © MyBB