Ion_Cannon Posted November 15, 2009 Share Posted November 15, 2009 Hello, i have a script that takes a billing address and a shipping address, it uses the following js to manage the country/states: $(document).ready(function(){ $('select#id_country').change(function(){ updateshipState(); }); updateshipState(); }); function updateshipState() { $('select#id_state option:not(:first-child)').remove(); var states = shipcountries[$('select#id_country').val()]; if( typeof(states) != 'undefined' ) { for (indexState in states) { //ie bug fix if (indexState != 'indexOf') $('select#id_state').append('<option value="'+indexState+'"'+ (shipSelectedCountry == indexState ? ' selected="selected' : '') + '">'+states[indexState]+'</option>'); } $('p.id_state:hidden').slideDown('slow'); } else $('p.id_state').slideUp('fast'); } and the script is called in php with the following: <script type="text/javascript"> // <![CDATA[ idSelectedCountry = {if isset($smarty.post.id_state)}{$smarty.post.id_state|intval}{else}false{/if}; countries = new Array(); {foreach from=$countries item='country'} {if isset($country.states)} countries[{$country.id_country|intval}] = new Array(); {foreach from=$country.states item='state' name='states'} countries[{$country.id_country|intval}]['{$state.id_state|intval}'] = '{$state.name|escape:'htmlall':'UTF-8'}'; {/foreach} {/if} {/foreach} //]]> </script> The php form uses this to select: <p class="required select"> <label for="id_country">{l s='Country'}</label> <select name="id_country" id="id_country"> <option value="">-</option> {foreach from=$shipcountries item=z} <option value="{$z.id_country}" {if ($smarty.post.id_country == $z.id_country)} selected="selected"{/if}>{$z.name|escape:'htmlall':'UTF-8'}</option> {/foreach} </select> <sup>*</sup> </p> <p class="required id_state select"> <label for="id_state">{l s='State'}</label> <select name="id_state" id="id_state"> <option value="">-</option> </select> <sup>*</sup> </p> My question is, this works great for the billing address part of the form but I want it to do the same thing for the shipping fields but I cannot get it to work. Would anyone have any ideas how I could make it work with my shipping section also on the same form? thanks Link to comment https://forums.phpfreaks.com/topic/181567-help-with-phpjs-in-form/ Share on other sites More sharing options...
Ion_Cannon Posted November 15, 2009 Author Share Posted November 15, 2009 Any tips anyone?? Link to comment https://forums.phpfreaks.com/topic/181567-help-with-phpjs-in-form/#findComment-957989 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.