Double dropdown box structure.

From: Date: Mon, 23 Sep 2002 05:27:07 +0000
Subject: Double dropdown box structure.
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-6014@lists.php.net to get a copy of this message
Hello, I'm having some trouble with this: I'm trying to get two dropdown boxes on my page, the second one beeing auto-populated by the selection in the first one. I use javascript for the auto-population and the data is from a mysql query. The problem I have is that I relly can't figure out the data structure that would do this. I got this working with Perl and no templating engine, but I can't get it working with a templating engine. Example: The first dropdown box contains customers 4, 10, 12. Do a query on relations table to get what contract goes with what customer: mysql> SELECT customer_id, cont_id FROM Relations; result: customer_id, cont_id 12, 00016 10, 00011 4, 00014 12, 00017 Then the javascript should look something like: // Assign dynamic values for the second dropdown box var custRel4 = new Array("contract 00014", "00014"); var custRel10 = new Array("contract 00011", "00011"); var custRel12 = new Array("contract 00017", "00017", "contract 00016", "00016"); // When some customer is selected in the first dropdown, auto-populate the second dropdown function set_jobs() { var select_customer = document.mainTKform.customer_id; var select_contract = document.mainTKform.contract_id; var selected_customer = select_customer.options[select_customer.selectedIndex].value; select_contract.options.length=0; if (selected_customer == "4") { for(var i=0; i<custRel4.length; i=i+2) { // custRel4[i], custRel4[i+1] means: take the first argument for option description and the second for value // ie. custRel4[i] = contract 00014 (what user sees) and custRel4[i+1] = 00014 (what gets passed to the next script) select_contract.options[select_contract.options.length] = new Option(custRel4[i], custRel4[i+1]); }} if (selected_customer == "10") { for(var i=0; i<custRel10.length; i=i+2) { select_contract.options[select_contract.options.length] = new Option(custRel10[i], custRel10[i+1]); }} if (selected_customer == "12") { for(var i=0; i<custRel12.length; i=i+2) { select_contract.options[select_contract.options.length] = new Option(custRel12[i], custRel12[i+1]); }} } and the html part is easy and obvious. But I can't seem to get how to store data so I can print the 'var custRel' arrays correctly with smarty and php. The problem is when one customer has multiple contracts (like customer 12 im my example)... I always get something like: var custRel4 = new Array("contract 00014", "00014"); var custRel10 = new Array("contract 00011", "00011"); var custRel12 = new Array("contract 00017", "00017" var custRel12 = new Array(" "contract 00016", "00016" ... My function is: {section name=i loop=$customers} {if $loop eq 0} var storage{$customers[i].customer_id} = new Array("{$customers[i].contract_id}", "{$customers[i].contract_id}" {$current = $customers[i].customer_id} {/if} {if $loop ne 0 and $current ne $customers[i].contract_id} ); var storage{$customers[i].customer_id} = new Array("{$customers[i].contract_id}", "{$customers[i].contract_id}" {$current = $customers[i].customer_id} {elseif $loop ne 0} ,"{$customers[i].contract_id}", "{$customers[i].contract_id}" {/if} {/section} If you have any idea about this, or anywhere where I can get further guidence about this, please let me know. Thanks! Marko mdinic@edaptivity.com

« previous php.smarty.general (#6014) next »