State/Province dropdown

rodsdesign 15 Feb, 2008
Hi all,

I'm sure you have used something like this - but in case you're always copying and pasting a drop down for states, I created an include that I have used a lot!

1. Copy and paste this code into a file (I call it stateselect.php) and put it somewhere within your joomla installation (I usually create a directory called myincludes)
Code for stateselect.php:
<select name='state' size='1'>
<option value=''>Choose a State</option>
<option value='AK' <?php if ($_POST['state'] == 'AK') echo 'selected='selected''; ?>>Alaska</option>
<option value='AL' <?php if ($_POST['state'] == 'AL') echo 'selected='selected''; ?>>Alabama</option>
<option value='AR' <?php if ($_POST['state'] == 'AR') echo 'selected='selected''; ?>>Arkansas</option>
<option value='AZ' <?php if ($_POST['state'] == 'AZ') echo 'selected='selected''; ?>>Arizona</option>
<option value='CA' <?php if ($_POST['state'] == 'CA') echo 'selected='selected''; ?>>California</option>
<option value='CO' <?php if ($_POST['state'] == 'CO') echo 'selected='selected''; ?>>Colorado</option>
<option value='CT' <?php if ($_POST['state'] == 'CT') echo 'selected='selected''; ?>>Connecticut</option>
<option value='DC' <?php if ($_POST['state'] == 'DC') echo 'selected='selected''; ?>>District of Columbia</option>
<option value='DE' <?php if ($_POST['state'] == 'DE') echo 'selected='selected''; ?>>Delaware</option>
<option value='FL' <?php if ($_POST['state'] == 'FL') echo 'selected='selected''; ?>>Florida</option>
<option value='GA' <?php if ($_POST['state'] == 'GA') echo 'selected='selected''; ?>>Georgia</option>
<option value='HI' <?php if ($_POST['state'] == 'HI') echo 'selected='selected''; ?>>Hawaii</option>
<option value='IA' <?php if ($_POST['state'] == 'IA') echo 'selected='selected''; ?>>Iowa</option>
<option value='ID' <?php if ($_POST['state'] == 'ID') echo 'selected='selected''; ?>>Idaho</option>
<option value='IL' <?php if ($_POST['state'] == 'IL') echo 'selected='selected''; ?>>Illinois</option>
<option value='IN' <?php if ($_POST['state'] == 'IN') echo 'selected='selected''; ?>>Indiana</option>
<option value='KS' <?php if ($_POST['state'] == 'KS') echo 'selected='selected''; ?>>Kansas</option>
<option value='KY' <?php if ($_POST['state'] == 'KY') echo 'selected='selected''; ?>>Kentucky</option>
<option value='LA' <?php if ($_POST['state'] == 'LA') echo 'selected='selected''; ?>>Louisiana</option>
<option value='MA' <?php if ($_POST['state'] == 'MA') echo 'selected='selected''; ?>>Massachusetts</option>
<option value='MD' <?php if ($_POST['state'] == 'MD') echo 'selected='selected''; ?>>Maryland</option>
<option value='ME' <?php if ($_POST['state'] == 'ME') echo 'selected='selected''; ?>>Maine</option>
<option value='MI' <?php if ($_POST['state'] == 'MI') echo 'selected='selected''; ?>>Michigan</option>
<option value='MN' <?php if ($_POST['state'] == 'MN') echo 'selected='selected''; ?>>Minnesota</option>
<option value='MO' <?php if ($_POST['state'] == 'MO') echo 'selected='selected''; ?>>Missouri</option>
<option value='MS' <?php if ($_POST['state'] == 'MS') echo 'selected='selected''; ?>>Mississippi</option>
<option value='MT' <?php if ($_POST['state'] == 'MT') echo 'selected='selected''; ?>>Montana</option>
<option value='NC' <?php if ($_POST['state'] == 'NC') echo 'selected='selected''; ?>>North Carolina</option>
<option value='ND' <?php if ($_POST['state'] == 'MD') echo 'selected='selected''; ?>>North Dakota</option>
<option value='NE' <?php if ($_POST['state'] == 'ME') echo 'selected='selected''; ?>>Nebraska</option>
<option value='NH' <?php if ($_POST['state'] == 'NH') echo 'selected='selected''; ?>>New Hampshire</option>
<option value='NJ' <?php if ($_POST['state'] == 'NJ') echo 'selected='selected''; ?>>New Jersey</option>
<option value='NM' <?php if ($_POST['state'] == 'NM') echo 'selected='selected''; ?>>New Mexico</option>
<option value='NV' <?php if ($_POST['state'] == 'NV') echo 'selected='selected''; ?>>Nevada</option>
<option value='NY' <?php if ($_POST['state'] == 'NY') echo 'selected='selected''; ?>>New York</option>
<option value='OH' <?php if ($_POST['state'] == 'OH') echo 'selected='selected''; ?>>Ohio</option>
<option value='OK' <?php if ($_POST['state'] == 'OK') echo 'selected='selected''; ?>>Oklahoma</option>
<option value='OR' <?php if ($_POST['state'] == 'OR') echo 'selected='selected''; ?>>Oregon</option>
<option value='PA' <?php if ($_POST['state'] == 'PA') echo 'selected='selected''; ?>>Pennsylvania</option>
<option value='PR' <?php if ($_POST['state'] == 'PR') echo 'selected='selected''; ?>>Puerto Rico</option>
<option value='RI' <?php if ($_POST['state'] == 'RI') echo 'selected='selected''; ?>>Rhode Island</option>
<option value='SC' <?php if ($_POST['state'] == 'SC') echo 'selected='selected''; ?>>South Carolina</option>
<option value='SD' <?php if ($_POST['state'] == 'SD') echo 'selected='selected''; ?>>South Dakota</option>
<option value='TN' <?php if ($_POST['state'] == 'TN') echo 'selected='selected''; ?>>Tennessee</option>
<option value='TX' <?php if ($_POST['state'] == 'TX') echo 'selected='selected''; ?>>Texas</option>
<option value='UT' <?php if ($_POST['state'] == 'UT') echo 'selected='selected''; ?>>Utah</option>
<option value='VA' <?php if ($_POST['state'] == 'VA') echo 'selected='selected''; ?>>Virginia</option>
<option value='VT' <?php if ($_POST['state'] == 'VT') echo 'selected='selected''; ?>>Vermont</option>
<option value='WA' <?php if ($_POST['state'] == 'WA') echo 'selected='selected''; ?>>Washington</option>
<option value='WI' <?php if ($_POST['state'] == 'WI') echo 'selected='selected''; ?>>Wisconsin</option>
<option value='WV' <?php if ($_POST['state'] == 'WV') echo 'selected='selected''; ?>>West Virginia</option>
<option value='WY' <?php if ($_POST['state'] == 'WY') echo 'selected='selected''; ?>>Wyoming</option>
<option value=''>Canadian Provinces</option>
<option value='AB' <?php if ($_POST['state'] == 'AB') echo 'selected='selected''; ?>>Alberta</option>
<option value='BC' <?php if ($_POST['state'] == 'BC') echo 'selected='selected''; ?>>British Columbia</option>
<option value='MB' <?php if ($_POST['state'] == 'MB') echo 'selected='selected''; ?>>Manitoba</option>
<option value='NB' <?php if ($_POST['state'] == 'NB') echo 'selected='selected''; ?>>New Brunswick</option>
<option value='NF' <?php if ($_POST['state'] == 'NF') echo 'selected='selected''; ?>>Newfoundland</option>
<option value='NT' <?php if ($_POST['state'] == 'NT') echo 'selected='selected''; ?>>Northwest Territories</option>
<option value='NS' <?php if ($_POST['state'] == 'NS') echo 'selected='selected''; ?>>Nova Scotia</option>
<option value='NU' <?php if ($_POST['state'] == 'NU') echo 'selected='selected''; ?>>Nunavut</option>
<option value='ON' <?php if ($_POST['state'] == 'ON') echo 'selected='selected''; ?>>Ontario</option>
<option value='PE' <?php if ($_POST['state'] == 'PE') echo 'selected='selected''; ?>>Prince Edward Island</option>
<option value='QC' <?php if ($_POST['state'] == 'QC') echo 'selected='selected''; ?>>Quebec</option>
<option value='SK' <?php if ($_POST['state'] == 'SK') echo 'selected='selected''; ?>>Saskatchewan</option>
<option value='YT' <?php if ($_POST['state'] == 'YT') echo 'selected='selected''; ?>>Yukon Territory</option>
</select>

2. in your form, where you'd normally put the <select> </select>, put
<?php include ( 'myincludes/stateselect.php' );?>


that's it - the states will be included in the form, and they'll be remembered if someone puts in the wrong text for image verification.

hope that helps someone🙂
GreyHead 16 Feb, 2008
Hi Rod,

This is neat - I like the idea of using and include file for this. It prompted me to go back and look to see if Joomla had a buil-in states list (it doesn't as far as i can see). However I did find some built in constructor code that lets you do this with less repetition
<?php
$USStateArray = Array(
'AK' => 'Alaska', 
'AL' => 'Alabama', 
'AR' => 'Arkansas', 
'AZ' => 'Arizona', 
'CA' => 'California', 
'CO' => 'Colorado', 
'CT' => 'Connecticut', 
'DC' => 'District of Columbia', 
'DE' => 'Delaware', 
'FL' => 'Florida', 
'GA' => 'Georgia', 
'HI' => 'Hawaii', 
'IA' => 'Iowa', 
'ID' => 'Idaho', 
'IL' => 'Illinois', 
'IN' => 'Indiana', 
'KS' => 'Kansas', 
'KY' => 'Kentucky', 
'LA' => 'Louisiana', 
'MA' => 'Massachusetts', 
'MD' => 'Maryland', 
'ME' => 'Maine', 
'MI' => 'Michigan', 
'MN' => 'Minnesota', 
'MO' => 'Missouri', 
'MS' => 'Mississippi', 
'MT' => 'Montana', 
'NC' => 'North Carolina', 
'MD' => 'North Dakota', 
'ME' => 'Nebraska', 
'NH' => 'New Hampshire', 
'NJ' => 'New Jersey', 
'NM' => 'New Mexico', 
'NV' => 'Nevada', 
'NY' => 'New York', 
'OH' => 'Ohio', 
'OK' => 'Oklahoma', 
'OR' => 'Oregon', 
'PA' => 'Pennsylvania', 
'PR' => 'Puerto Rico', 
'RI' => 'Rhode Island', 
'SC' => 'South Carolina', 
'SD' => 'South Dakota', 
'TN' => 'Tennessee', 
'TX' => 'Texas', 
'UT' => 'Utah', 
'VA' => 'Virginia', 
'VT' => 'Vermont', 
'WA' => 'Washington', 
'WI' => 'Wisconsin', 
'WV' => 'West Virginia', 
'WY' => 'Wyoming' );
foreach ( $USStateArray as $abb => $name ) {
  $options[] = mosHTML::makeOption($abb, $name);
}
$select = mosHTML::selectList($options, 'state[]', 'size="1"', 'value', 'text', $_POST['state']);
echo $select;
?>
<br />
<input name='state[]' type='hidden' />
This works in a ChronoForms form. A couple of things to notice though: (a) I used the mosHTML library (documented in the Joomla Developers Manual) really just to see if it works, you could do the same with a foreach loop to generate <option> tags. (b) to get the result into ChronoForms I had to add that dummy hidden input - it's only there so that when ChronoForms parses the HTML it finds the field name.

Bob
sailsmart 08 May, 2008
You mean I have to put in all this code and it's going to post the drop down answer? Do I have to build arrays?;)
Max_admin 09 May, 2008
Both the codes posted will work fine, just pick anyone of them, Bob used the Joomla built in functions to make the dropdown through arrays, it makes it easier to show the selected entry too!

Cheers

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
kai920 15 May, 2008
Hi guys,

I am trying to utilize similar code in a form I am building. I would like to eventually move the array code into a PHP file so that it can be edited easily as the array of list values could change often.

Here is a simple example I tried to adapt - is there something wrong with this code? :dry:


<?php 
$Category = Array( 
'Audio' => 'Audio',
'Blog' => 'Blog' );

foreach ( $Category as $cat => $category ) { 
  $options[] = mosHTML::makeOption($cat, $category); 
} 
$select = mosHTML::selectList($options, 'category[]', 'size="1"', 'value', 'text', $_POST['category']); 
echo $select; 
?> 
<br /> 
<input name='category[]' type='hidden' />
GreyHead 15 May, 2008
Hi kai920,

It looks OK to my eyeball.

What happens when you use it?

Bob
kai920 15 May, 2008
hmm nothing happens! The form becomes blank when I paste the above code in.

That's why I thought something was wrong with it...

I tried to turn on debugging in Chronoforms - but don't see any debugging info.

Oh, I should mention I am using J!1.5.x - is that why I am getting a blank form?
GreyHead 15 May, 2008
Hi Kai920,

Missed one, you've got confused quoted around size - should be 'size="1"' I also got a PHP notice about an undefined index. Modified code is

<?php  
$Category = Array(  
'Audio' => 'Audio', 
'Blog' => 'Blog' ); 
$options = array();
if ( !isset($_POST['category']) ) {
  $_POST['category'] = "";
}
foreach ( $Category as $cat => $category ) {  
  $options[] = mosHTML::makeOption($cat, $category);  
}  
$select = mosHTML::selectList($options, 'category[]', 
  'size="1"', 'value', 'text', $_POST['category']);  
echo $select;  
?> 
Bob
kai920 15 May, 2008
Hi Bob,

Many thanks for your reply. Maybe I am misunderstanding what the code is supposed to do :blush:

I used the code as posted immediately above, I thought I would see a pull down list with "Audio" and "Blog"... is that not what should show up?

Or perhaps something is still wrong with the code? Because I do not see the J template, nor the submit button. Screenshot:

State/Province dropdown image 1
GreyHead 15 May, 2008
Hi Kai920,

Sorry trying to do two things at once I stuck it in a copy of the test form and forgot to delete the other code. I'll amend my post now. That said, I get the drop-down OK.

Bob State/Province dropdown image 2
kai920 15 May, 2008
Could there be something wrong with my Joomla setup? Very strange : I am getting a blank screen with only the following code in the form. No Joomla template, no drop down list, nothing.

<?php   
$Category = Array(   
'Audio' => 'Audio',  
'Blog' => 'Blog' );  
$options = array(); 
if ( !isset($_POST['category']) ) { 
  $_POST['category'] = ""; 
} 
foreach ( $Category as $cat => $category ) {   
  $options[] = mosHTML::makeOption($cat, $category);   
}   
$select = mosHTML::selectList($options, 'category[]',  
  'size="1"', 'value', 'text', $_POST['category']);   
echo $select;   
?> 
<input name='category[]' type='hidden' />


The HTML source only has one line:
<form name="ChronoContact_quotes" id="ChronoContact_quotes" method="post" action="index.php?option=com_chronocontact&task=send&chronoformname=quotes" >
GreyHead 15 May, 2008
Hi Kai,

It looks Ok to me - but there may still be a typo in there. Set your site to Error Reporting Maximum; comment out most of the lines of code and refresh the form, uncomment a few more lines until you find where error is.

Bob
kai920 15 May, 2008
Hi Bob,

Thanks for the hint.

I set error_reporting = E_ALL and display_errors = On and finally got a meaningful error msg.

Fatal error: Class 'mosHTML' not found in /home/joomla/components/com_chronocontact/chronocontact.html.php(83) : eval()'d code on line 10

I assume Joomla 1.5.x still uses moSHTML?
GreyHead 15 May, 2008
Hi kai920,

I must have Legacy mode on. Try JHTML instead see here for docs.

Bob
kai920 15 May, 2008
Ah-ha! Thanks for the clarification once again :side:

I turned on the legacy bot and it works nicely now.

I did come across the api link, but found it strange there was no "selectList". Is it hidden under another class?

Never mind, found something HERE!
kai920 15 May, 2008
So following on the previous link, I tried to use the JHTMLSelect class... but it was giving me a "class not found error". So I thought I had to access the file /joomla/html/html/select.php somehow. I then tried all sorts of stuff, took a long time (very long time it seems, but it's nice to try to figure out things on your own once in a while). I finally figured out to do this:

include_once JPATH_ROOT . "libraries/joomla/html/html/select.php";


<?php   
$Category = Array(   
'Audio' => 'Audio',  
'Blog' => 'Blog' );  
$options = array(); 
if ( !isset($_POST['category']) ) { 
  $_POST['category'] = ""; 
} 

include_once JPATH_ROOT . "/libraries/joomla/html/html/select.php";

foreach ( $Category as $cat => $category ) {   
  $options[] = JHTMLSelect::option($cat, $category);   
}   
$select = JHTMLSelect::genericlist($options, 'category[]',  
  'size="1"', 'value', 'text', $_POST['category']);   
echo $select;   

?>  



Woohoo. This works for 1.5 w/o legacy mode!🙂 But is this the best way, i.e. acceptable practice?

BTW - it seems SAVE and APPLY on the form has the same effects? They both bring me out to the list of forms... it would be nice if APPLY would just save and keep you at the same screen..
GreyHead 16 May, 2008
Hi kai920,

Well done, I'm sure that there is some *magic* way of loading the JHTML libraries but I don't know what it is . . .

And, yes 'Apply' is broken in CF for J1.5 and it's very frustrating!!

Bob
kai920 16 May, 2008
Hi Bob,

Couldn't have done it without your patient guidance, so many thanks for that🙂

I found the "proper" way is supposedly using jimport("joomla.html.html.select); but I also got a class not found with this. investigating why...

It's amazing how frustrating just a couple extra clicks can be🙂
kai920 16 May, 2008
Hi Bob,

To clarify the 2nd post in this thread: I can put the hidden field anywhere inside the form right?

i.e. all the various

<input name='category[]' type='hidden' />
can be grouped together at the beginning/end of the form? Or must they immediately follow the select list php code?
GreyHead 17 May, 2008
Hi kai920,

They can go anywhere. I tend to put them in a group at the end just after the submit button. If there are any odd spaces that show up they are usually 'invisible' down there.

Bob
kai920 23 Jun, 2008
Hi Bob,

Hope you're well. Another question I had about the hidden category - in the database the data is being saved with an extra comma at the end. For example, I selected Audio in the list below, and when viewing the db it shows "Audio,"

My select list does not appear to have any comma's. Is this normal behavior?

<select size="1" id="Category" name="Category[]" class="validation-passed"><option selected="selected" value=""/><option value="Audio">Audio</option><option value="Blog">Blog</option><option value="Book review">Book review</option><option value="Column">Column</option><option value="Editorial">Editorial</option><option value="Film">Film</option><option value="Letter">Letter</option><option value="Media release">Media release</option><option value="Newsletter">Newsletter</option><option value="Opinion">Opinion</option><option value="Poll">Poll</option><option value="Series">Series</option><option value="Speech">Speech</option><option value="Transcript">Transcript</option><option value="Video">Video</option><option value="Web Page">Web Page</option></select>
GreyHead 23 Jun, 2008
Hi kai 20,

Not sure, I'd guess there's a stray something in the code - so you want to send me a form backup?

Bob
kai920 03 Jul, 2008
Hi Bob,

Thanks for the offer, I'm going to email the backup to you now🙂

Cheers
GreyHead 05 Jul, 2008
Hi kai920,

What you've sent looks OK. Please will you also send the category.php file so that I can see what's in that.

Bob
tysonbravo 14 Oct, 2008
Hi Bob,

I attempted to insert a State Field Drop Down using the instructions you gave above, and ended up with the following error msg:

Parse error: syntax error, unexpected T_LNUMBER in /home/txweb/public_html/components/com_chronocontact/chronocontact.html.php(320) : eval()'d code on line 60


I just cut and paste the constructor code above into the Form HTML. Did I miss a setp?

I may be attempting something that is simply out of my league (i'm no PHP programmer....which is why I'm using Joomla for CMS)...
GreyHead 14 Oct, 2008
Hi tysonbravo,

You are pobably missing a ; in the form html. Check around line 60. If you don't see anything cut and paste the form html here and I'll take a look.

Bob
tysonbravo 14 Oct, 2008
This is my entire Form HTML. I'm not really sure where line 60 starts. I've separated the various elements into three sections. First are my text boxes/areas, second is the PHP constructor code for state drop down, third is Captcha. I don't see that anything is missing, but then again I'm not expert. I just copied what was written in this thread above...
<div  class="form_item"><div class="form_element cf_textbox"><label class="cf_label">Name</label><input class="cf_inputbox required" maxlength="150" size="30" id="text_0" name="text_0" type="text"></div><div class="clear"> </div></div><div  class="form_item"><div class="form_element cf_textbox"><label class="cf_label">Email</label><input class="cf_inputbox required validate-email" maxlength="150" size="30" id="text_1" name="text_1" type="text"></div><div class="clear"> </div></div><div  class="form_item"><div class="form_element cf_textarea"><label class="cf_label">Comments/Questions:</label><textarea class="cf_inputbox required" rows="10" id="text_2" cols="30" name="text_2"></textarea></div><div class="clear"> </div></div>

 <?php
    $USStateArray = Array(
    'AK' => 'Alaska',
    'AL' => 'Alabama',
    'AR' => 'Arkansas',
    'AZ' => 'Arizona',
    'CA' => 'California',
    'CO' => 'Colorado',
    'CT' => 'Connecticut',
    'DC' => 'District of Columbia',
    'DE' => 'Delaware',
    'FL' => 'Florida',
    'GA' => 'Georgia',
    'HI' => 'Hawaii',
    'IA' => 'Iowa',
    'ID' => 'Idaho',
    'IL' => 'Illinois',
    'IN' => 'Indiana',
    'KS' => 'Kansas',
    'KY' => 'Kentucky',
    'LA' => 'Louisiana',
    'MA' => 'Massachusetts',
    'MD' => 'Maryland',
    'ME' => 'Maine',
    'MI' => 'Michigan',
    'MN' => 'Minnesota',
    'MO' => 'Missouri',
    'MS' => 'Mississippi',
    'MT' => 'Montana',
    'NC' => 'North Carolina',
    'MD' => 'North Dakota',
    'ME' => 'Nebraska',
    'NH' => 'New Hampshire',
    'NJ' => 'New Jersey',
    'NM' => 'New Mexico',
    'NV' => 'Nevada',
    'NY' => 'New York',
    'OH' => 'Ohio',
    'OK' => 'Oklahoma',
    'OR' => 'Oregon',
    'PA' => 'Pennsylvania',
    'PR' => 'Puerto Rico',
    'RI' => 'Rhode Island',
    'SC' => 'South Carolina',
    'SD' => 'South Dakota',
    'TN' => 'Tennessee',
    'TX' => 'Texas',
    'UT' => 'Utah',
    'VA' => 'Virginia',
    'VT' => 'Vermont',
    'WA' => 'Washington',
    'WI' => 'Wisconsin',
    'WV' => 'West Virginia',
    'WY' => 'Wyoming' );
    foreach ( $USStateArray as $abb => $name ) {
      $options[] = mosHTML::makeOption($abb, $name);
    }
    $select = mosHTML::selectList($options, 'state[]', 'size='1'', 'value', 'text', $_POST['state']);
    echo $select;
    ?>
    <br />
    <input name='state[]' type='hidden' />


{imageverification}<div  class="form_item"><div class="form_element cf_button"><input value="Submit" name="undefined" type="submit"></div><div class="clear"> </div></div>
obisi7 14 Oct, 2008
Bob--

I used your code and saved it as stateselect.php. Saved the file to a folder called myincludes off of my public_html folder.
Replaced <select> </select> with the code Kai suggested in the exact position it would have been.

I pasted the form code into the form code of CHronoforms, created, connected, and published the table. However, I am getting this error that I have no idea what is causing it or how to fix it. Did I need to still use the <select> </select> tag? What am i doing wrong?

DB function failed with error number 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-page1 ORDER BY cf_id LIMIT 0,20' at line 1 SQL=SELECT * FROM jos_chronoforms_coForm-page1 ORDER BY cf_id LIMIT 0,20



thx
Max_admin 14 Oct, 2008
Hi obisi,

it looks like your table name is not good, it has -page1, change this to _page1

cheers

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 15 Oct, 2008
Hi obisi7,

There are some messed up quotes round 'size='1'', (looks as though that was in my original code - I've gone abck and corrected it) and the code was written for Joomla 1.0, for J 1.5 it has changed a little.

Towards the end there is a 'foreach' loop. Here's the corrected code there. For Joomla 1.0
        foreach ( $USStateArray as $abb => $name ) {
          $options[] = mosHTML::makeOption($abb, $name);
        }
        $select = mosHTML::selectList($options, 'state[]', 'size="1"', 'value', 'text', $_POST['state']);
        echo $select;
and Joomal 1.5 native
        foreach ( $USStateArray as $abb => $name ) {
          $options[] = JHTML::_('select.option', $abb, $name);
        }
        $select = JHTML::_('select.genericlist', $options, 'state[]', 'size="1"', 'value', 'text', JRequest::getVar('state', '', 'post'));
        echo $select;
Bob

PS Here's the complete Joomla 1.5 State&Province select list
    <?php
        $USStateArray = Array(
        'AK' => 'Alaska',
        'AL' => 'Alabama',
        'AR' => 'Arkansas',
        'AZ' => 'Arizona',
        'CA' => 'California',
        'CO' => 'Colorado',
        'CT' => 'Connecticut',
        'DC' => 'District of Columbia',
        'DE' => 'Delaware',
        'FL' => 'Florida',
        'GA' => 'Georgia',
        'HI' => 'Hawaii',
        'IA' => 'Iowa',
        'ID' => 'Idaho',
        'IL' => 'Illinois',
        'IN' => 'Indiana',
        'KS' => 'Kansas',
        'KY' => 'Kentucky',
        'LA' => 'Louisiana',
        'MA' => 'Massachusetts',
        'MD' => 'Maryland',
        'ME' => 'Maine',
        'MI' => 'Michigan',
        'MN' => 'Minnesota',
        'MO' => 'Missouri',
        'MS' => 'Mississippi',
        'MT' => 'Montana',
        'NC' => 'North Carolina',
        'MD' => 'North Dakota',
        'ME' => 'Nebraska',
        'NH' => 'New Hampshire',
        'NJ' => 'New Jersey',
        'NM' => 'New Mexico',
        'NV' => 'Nevada',
        'NY' => 'New York',
        'OH' => 'Ohio',
        'OK' => 'Oklahoma',
        'OR' => 'Oregon',
        'PA' => 'Pennsylvania',
        'PR' => 'Puerto Rico',
        'RI' => 'Rhode Island',
        'SC' => 'South Carolina',
        'SD' => 'South Dakota',
        'TN' => 'Tennessee',
        'TX' => 'Texas',
        'UT' => 'Utah',
        'VA' => 'Virginia',
        'VT' => 'Vermont',
        'WA' => 'Washington',
        'WI' => 'Wisconsin',
        'WV' => 'West Virginia',
        'WY' => 'Wyoming' );
        foreach ( $USStateArray as $abb => $name ) {
          $options[] = JHTML::_(select.option, $abb, $name);
        }
        $select = JHTML::_('select.genericlist', $options, 'state[]', 'size="1"', 'value', 'text', JRegistry::getVar('state', '', 'post'));
        echo $select;
        ?>
obisi7 15 Oct, 2008
Bob and Max--

Thx to you both. I made the suggested corrections but I still have the same problems as follows:

1. The state selection input field does not show up in my form though I did exactly as Kai920 advised merely replacing his code with the modified version from Bob,

2. The list menu for applicant title (created in Dreamweaver) only shows the default selection and no arrows to see other 6 options. I discovered there is no dropdown form field in Dreamweaver CS3 but CF has it in the form wizard. Is there a way I can import the code from Dreamweaver and complete the design using CF form wizard or vice versa?

3. The file upload creadted in Dreamweaver is also not accepting the attributes (for file type restriction and whether file upload is even allowed) set in CF, How does one enable this action? The fieldname for the "file upload"in my form is passport and I specified a code like: passport:jpg|gif|png to restrict file type. This worked fine using the J1.0 version but not sure what is going on in J1.5

I will be most grateful if you can help me resolve these three main issues before I have to code remaining 345 forms.

P.S. I've not included a submit button yet until the form structure and behavior is right before enabling any data entry and validation,

Thx
obisi7 15 Oct, 2008
btw,

my url is <!-- w --><a class="postlink" href="http://www.myriversstate.com/rsg">www.myriversstate.com/rsg</a><!-- w --> and the form is accessible via the menu link: Apply for CO

thx
GreyHead 15 Oct, 2008
Hi obisi7,

It's hard to tell what's happening without seeing the output. I suggest that you set Error Reporting to Maximum in your site config while you are developing, and make sure that form Debug is on.

No idea about the State selector, I had it running in Joomla 1.5.7 CF 3.0 this morning.

The Title selector on your form needs size="4" or more so that you can see the scroll bar

There has to be a select box in Dreamweaver CS3 . . . but I don't use it so can't help there . . . They are easy enough to code by hand, or from the CF wizard.

The file attributes have changed in v3.0 you need to add a bit to show the max+min sizes - passport:jpg|gif|png{20000-0} - see the red help prompt on the File Uploads tab

Bob
obisi7 15 Oct, 2008
thx bob. I had updated my situation by providing a url to see the output:

<!-- w --><a class="postlink" href="http://www.myriversstate.com/rsg/">www.myriversstate.com/rsg/</a><!-- w --> and select '"Apply for CO'from the main menu. I will adjust other areas as you commented. You're a big help so is Max. I am still checking Dreamweaver cs3 for a select option but all i see now is the list/menu and Jump Menu options for element selection.

From your advice, I guess I should create a form in form wizard and then copy the code into Dreamweaver whcih allows me greater flexibility for layout.

Thx,
Max_admin 15 Oct, 2008
Hi Obisi,

I just checked DW CS3 and yes it doesn't have a dropdown thing unless its somewhere I can't find, try to google "how to make a dropdown in dreamweaver CS3"

the dropdowns code is is easy to copy/paste/edit, it will follow this model :

<select name="dropdownname">
<option value="option1value">option1 text</option>
</select>


Cheers

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
tysonbravo 15 Oct, 2008
I'm just curious, why even use this PHP Constructor code for the state list, when the Form Wizard seems like it can do it just fine and without all the hassle? Anybody...??
GreyHead 15 Oct, 2008
Hi tysonbravo,

No real reason, the code predates the wizard and should work as a cut and paste drop in for a frequently used form element. It's still a lot easier than getting the list of states in the Options box. But entirely a matter of taste; I happen to prefer to use the Joomla helpers when I can and prefer the array structures to having long lists of <option> tags.

Bob
obisi7 15 Oct, 2008
Thank you all. I found a way to do select in Dreamweaver CS3. It is the same form element tagged list/menu. Once created one need to select an option of menu instead of a list and voila!

It is also true that one can use this route instead of the array option, but I also like the idea of a clean form code with the ability to change one file instead of several form fields that may contain a state deopdown menu. It is all a question of preference.

Though the code is still not working for me, I will use the program's select option for now till I can get the code to work.
boogieman 14 Nov, 2008
Hi Guys,

I'm not advanced or anything but I am trying to go one step further with this code and generate an action using the country drop list also. I would like to select "Country: United States" then only have the US States populate the "State\Province" field. If i Select "Country: Canada" then the Canadian provinces would populate the "State\Province Field." Can anyone assist me with this?

~Thanks :o
GreyHead 14 Nov, 2008
Hi Boogieman,

You can do this with a little JavaScript. If you Google 'javascript select' you'll find many solutions. Probably neatest would be to choose one using the MooTools library which is loaded by Joomla 1.5.

I could write some code to do this but not for a day or two as I'm still catching up with a load of stuff from my trip.

Bob
GreyHead 15 Nov, 2008
Hi boogieman,

Here's a demonstration form of this kind of dropdown using a little JavaScript and MooTools. Here's the form html:
<div id='country'>
<select id='country_list' name='country_list' style='width:160px;' onChange='change_country();' >
    <option value='canada'>Canada</option>
    <option value='usa' selected='selected' >USA</option>
</select>
</div>

<div id='usa' class='select' style='display:block;' >
<select id='state_list' name='state_list' style='width:160px;' >
    <option value='Alabama'>Alabama</option>
    <option value='Alaska'>Alaska</option>
    <option value='Arizona'>Arizona</option>
</select>
</div>

<div id='canada'  class='select' style='display:none;' >
<select id='state_list' name='state_list' style='width:160px;' >
    <option value='Alberta'>Alberta</option>
    <option value='British Columbia'>British Columbia</option>
    <option value='Manitoba'>Manitoba</option>
</select>
</div>
<input type='submit' name='Submit' value='submit' />
and the JavaScript:
function change_country()
{
    var country = $('country_list');
    var selects = $$('div.select');
    for ( var i = 0; i < selects.length; i++ ) {
        if ( selects[i].id == country.value ) {
            selects[i].style.display = 'block';
        } else {
            selects[i].style.display = 'none';
        }
    }
}
You can extend this to more than one country by adding extra options in the country_list selector and a corresponding div for the state_selector. The value in the country selector *must* match the id of the corresponding div.

Bob
boogieman 15 Nov, 2008
Thanks Bob. I apprciate you taking the time to answer my questions! I have one more is it possible to change the drop down option to a Text Box? Example a user selected Mexico for Country, then I would have the State\Province drop down option be replaced with a simple text box. ~Thanks.
GreyHead 16 Nov, 2008
Hi Boogieman,

It should be straightforward, all the code does is hide or show the divs and their contents.
    <div id='country'>
    <select id='country_list' name='country_list' style='width:160px;' onChange='change_country();' >
        <option value='canada'>Canada</option>
        <option value='usa' selected='selected' >USA</option>
        <option value='mexico' >Mexico</option>
    </select>
    </div>

    <div id='usa' class='select' style='display:block;' >
    <select id='state_list' name='state_list' style='width:160px;' >
        <option value='Alabama'>Alabama</option>
        <option value='Alaska'>Alaska</option>
        <option value='Arizona'>Arizona</option>
    </select>
    </div>

    <div id='canada'  class='select' style='display:none;' >
    <select id='state_list' name='state_list' style='width:160px;' >
        <option value='Alberta'>Alberta</option>
        <option value='British Columbia'>British Columbia</option>
        <option value='Manitoba'>Manitoba</option>
    </select>
    </div>

    <div id='mexico'  class='select' style='display:none;' >
    <input type='text' name='state_list' style='width:160px;' value='' />
    </div>
    <input type='submit' name='Submit' value='submit' />

Bob
picsoung 16 Feb, 2009
hey😀
sorry to up the topic but i got a problem i try this solution on one of my form.
But when i submit it. The value taken is the first row of the last menu.

this is my code :
<div class="form_element cf_dropdown">
		<label class="cf_label">Category</label>
			<div id ='category'>
			<select name="objectcat" size="1" id="objectcat" class="cf_inputbox validate-selection" onChange='change_subcat();'>
			<option value="">Please select</option><!--Empty line for ChronoForm required error --!>
			<?php //this code permit to use dynamic access to category list
			
				$query= "SELECT * FROM `#__itemcat` ;";
		$db->setQuery($query);
		$db->query();
		$result=$db->loadRowList();
		
		foreach($result as $cle =>$val):?>			 	
			<option value="<?php echo $val[1]; ?>"><?php echo stripslashes($val[1]); ?></option>
		<?php 
		endforeach; ?>
		</select>
		<script type="text/javascript">
			function change_subcat()
{
    var cat = $('objectcat');
    var selects = $$('div.select');
    for ( var i = 0; i < selects.length; i++ ) {
        if ( selects[i].id == cat.value ) {
            selects[i].style.display = 'block';
        } else {
            selects[i].style.display = 'none';
        }
    }
}
		</script>
	</div>
		<div class="clear"> </div>
	</div>
	
	<div class="form_item" >
	<div class="form_element cf_dropdown">
		<label class="cf_label">Subcategory</label>
			<?php foreach($result as $cle =>$val):?>			 	
			<div id="<?php echo $val[1]; ?>" class='select' style='display:none;'>
				<select id ='objectsubcat' name='objectsubcat' style='width:160px;'>
					<?php
					$idcle=$cle+1;
					$query= "SELECT * FROM `#__itemsubcat` WHERE `catid`='$idcle';";
					$db->setQuery($query);
					$db->query();
					$subcat_result=$db->loadRowList();
					
					foreach($subcat_result as $subcat_cle =>$subcat_val): ?>			 	
						<option value="<?php echo $subcat_val[2]; ?>"><?php echo stripslashes($subcat_val[2]); ?></option>
					<?php 
					endforeach; ?>
				</select>
 			</div>
		<?php endforeach; ?>
	</div>


First i got a list for Category then list for Second category depending on the first one.
Categories name are stored in a table, same for subcat name.

Categories are identified by an unique id.
And subcat by an unique id and a idcat referred to category id.

Is there something that i did wrong ?

thanks😉
Max_admin 16 Feb, 2009
Hi picsoung,

what are you trying to do exactly ?

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
picsoung 17 Feb, 2009
oh oh... my post wasn't easy to understandface-meh-blank

so i have 2 dropdown
1 for category 1 for subcategory.

I have that the when i select a category for example "Computer" the second dropdown show all the subcategory coresponding to this category, like "Laptop","Home Pc", Notebook"

to do that i have a table Cat with two fields
'id' and 'name'
and a subcat table
'id' 'catid' 'name'

In my table i got 3 category, so 3 dropdown for subcategory but only one is available and showed. That is ok.

But wheen i clik on Submit button to end all the infos about my product (Name, Model, Cat, and Subcat)
The value $_POST['objectsubcat'] is not the one i select but the first row on the last dropdown. So it's wrong.
How this could happen ?

Hope this is more clearface-meh-blank
Max_admin 17 Feb, 2009
I think this line is wrong:
<option value="<?php echo $val[1]; ?>"><?php echo stripslashes($val[1]); ?></option>


it needs to be
<option value="<?php echo $val; ?>"><?php echo stripslashes($val); ?></option>


Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
picsoung 18 Feb, 2009
no it's ok because
i want to '1' column corresponding to 'name' column in my table category :
id name

if i replace by $val... result is Array Array Array..face-meh-blank
picsoung 18 Feb, 2009
is difficult to understand what i said... or from where comes from the problem ?face-meh-blank

sorry if i up the topic..
Max_admin 18 Feb, 2009
try to make:
 $result=$db->loadRowList();
      
      foreach($result as $cle =>$val):?>             
         <option value="<?php echo $val[1]; ?>"><?php echo stripslashes($val[1]); ?></option>
      <?php
      endforeach; ?>


as

 $result=$db->loadObjectList();
      
      foreach($result as $val):?>             
         <option value="<?php echo $val->name; ?>"><?php echo stripslashes($val->name); ?></option>
      <?php
      endforeach; ?>
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Ford Warrior 24 Feb, 2009
complete newbie to chronoforms so please bare with me .....

have 1 drop down list called Make, it has various options

then I have another drop down list called Model, it also has various options

if I select from Make - the option "Make 1" I wish to have only the options relevant to Make 1 displayed in the Model drop down list box.

should I not select anything from the Make drop down list box, the Model drop down list box should display "Select Model".

Will appreciate any help with this as the above posts did not make much sense :?
picsoung 24 Feb, 2009

try to make:

 $result=$db->loadRowList();
      
      foreach($result as $cle =>$val):?>             
         <option value="<?php echo $val[1]; ?>"><?php echo stripslashes($val[1]); ?></option>
      <?php
      endforeach; ?>

as
 $result=$db->loadObjectList();
      
      foreach($result as $cle => $val):?>             
         <option value="<?php echo $val->name; ?>"><?php echo stripslashes($val->name); ?></option>
      <?php
      endforeach; ?>




hey😀
i tried your tip... but it doesn't work😟
when i apply it to "Category" dropdown the subcategory dropdown is doesn't active when i select a category. And the rest of the form is not showed...
So i tried to apply it to thse second dropdown. Is working... but result is the same... another row value is taken, not the one i selected...

here is my code :

<div class="form_item" >
		<input type='hidden' name='email' value='<?php echo $user->email; ?>' />
		<div class="form_element cf_dropdown">
		<label class="cf_label">Category</label>
			<div id ='category'>
			<select name="objectcat" size="1" id="objectcat" class="cf_inputbox validate-selection" onChange='change_subcat();'>
			<option value="">Please select</option><!--Empty line for ChronoForm required error --!>
			<?php //this code permit to use dynamic access to category list
			
				$query= "SELECT * FROM `#__itemcat` ;";
		$db->setQuery($query);
		$db->query();
		$result=$db->loadRowList();
		
		foreach($result as $cle =>$val):?>			 	
			<option value="<?php echo $val[1]; ?>"><?php echo stripslashes($val[1]); ?></option>
		<?php 
		endforeach; ?>
		</select>
		<script type="text/javascript">
			function change_subcat()
{
    var cat = $('objectcat');
    var selects = $$('div.select');
    for ( var i = 0; i < selects.length; i++ ) {
        if ( selects[i].id == cat.value ) {
            selects[i].style.display = 'block';
        } else {
            selects[i].style.display = 'none';
        }
    }
}
		</script>
	</div>
		<div class="clear"> </div>
	</div>
	
	<div class="form_item" >
	<div class="form_element cf_dropdown">
		<label class="cf_label">Subcategory</label>
			<?php foreach($result as $cle =>$val):?>			 	
			<div id="<?php echo $val[1]; ?>" class='select' style='display:none;'>
				<select id ='objectsubcat' name='objectsubcat' style='width:160px;'>
					<?php
					$idcle=$cle+1;
					$query= "SELECT * FROM `#__itemsubcat` WHERE `catid`='$idcle';";
					$db->setQuery($query);
					$db->query();
					$subcat_result=$db->loadObjectList();
					
					foreach($subcat_result as $subcat_cle =>$subcat_val): ?>			 	
						<option value="<?php echo $subcat_val->name; ?>"><?php echo stripslashes($subcat_val->name); ?></option>
					<?php 
					endforeach; ?>
				</select>
 			</div>
		<?php endforeach; ?>
	</div>


thanks for your help😉
GreyHead 24 Feb, 2009
Hi picsoung,

This version works
<?php
$user =& JFactory::getUser();
$db =& JFactory::getDBO();
?>
<div class="form_item" >
      <input type='hidden' name='email' value='<?php echo $user->email; ?>' />
      <div class="form_element cf_dropdown">
      <label class="cf_label">Category</label>
         <div id ='category'>
         <select name="objectcat" size="1" id="objectcat" class="cf_inputbox validate-selection" onChange='change_subcat();'>
         <option value="">Please select</option><!--Empty line for ChronoForm required error --!>
<?php //this code permit to use dynamic access to category list
         
      $query= "SELECT * FROM `#__itemcat` ;";
      $db->setQuery($query);
      $result = $db->loadRowList();
      
      foreach($result as $cle => $val): 
        echo "<option value='".$val[1]."'>".stripslashes($val[1])."</option>";
      endforeach; 
?>
      </select>
   </div>
   <div class="clear"> </div>
</div>
   
<div class="form_item" >
   <div class="form_element cf_dropdown">
      <label class="cf_label">Subcategory</label>
<?php
         foreach($result as $cle =>$val):
            echo "<div id='".$val[1]."' class='select' style='display:none;'>";
?>
            <select id ='objectsubcat' name='objectsubcat' style='width:160px;'>
<?php
               $idcle = $cle + 1;
               $query= "
                 SELECT * FROM `#__itemsubcat` 
                   WHERE `catid`='$idcle';";
               $db->setQuery($query);
               $subcat_result = $db->loadObjectList();
               foreach($subcat_result as $subcat_cle =>$subcat_val):         
                  echo "<option value='".$subcat_val->name."'>".stripslashes($subcat_val->name)."</option>";
               endforeach; 
?>
            </select>
         </div>
<?php
        endforeach; 
?>
</div>
Note: JavaScript is moved to the JavaScript box.

I'm not sure what was broken before as I cleaned up various bits - the biggest problem was that $db wasn't defined.

Bob
picsoung 06 Mar, 2009
hey😀
thanks for your help
that is working well know.

But i got a problem to adapt the code to another situation : when i want to auto-filled with values taken from a database.
Then update infos.

<div class="form_item" >
	<input type='hidden' name='email' value='<?php echo $user->email; ?>' />
	<div class="form_element cf_dropdown">
		<label class="cf_label">Category</label>
		<div id ='category'>
         <select name="objectcat" size="1" id="objectcat" class="cf_inputbox validate-selection" onChange='change_subcat();'>
         <option value="">Please select</option><!--Empty line for ChronoForm required error --!>
<?php //this code permit to use dynamic access to category list
         
      $query= "SELECT * FROM `#__itemcat` ;";
      $db->setQuery($query);
      $result = $db->loadObjectList();
      
      foreach($result as $cle => $val):
      if(($val->id)==$catid):?>
			<option selected="selected" value="<?php echo $val->id; ?>"><?php echo stripslashes($val->name); ?></option>
			<?php else: ?>			 	
		<option value="<?php echo $val->id; ?>"><?php echo stripslashes($val->name); ?></option>
	<?php 
		endif;
	endforeach; ?>
		</select>
	   </div>
	
	</div>
	<div class="clear">
	</div>
</div>

<div class="form_item" >
   <div class="form_element cf_dropdown">
      <label class="cf_label">Subcategory</label>
<?php
         foreach($result as $cle =>$val):
         echo 'val id '.$val->id;
         if($val->id==$catid):
            echo "<div id=\"$val->id\" class='select' style='display:block;'>";
            else:
            echo "<div id=\"$val->id\" class='select' style='display:none;'>";
            endif;
?>
            <select id ='objectsubcat' name='objectsubcat' style='width:160px;' size="1">
<?php
               echo 'cat id '.$catid. 'val id '.$val->id;
               $query= "SELECT * FROM `#__itemsubcat` WHERE `catid`='$val->id';";
               $db->setQuery($query);
               $subcat_result = $db->loadObjectList();
             
               foreach($subcat_result as $subcat_cle =>$subcat_val):
               if($subcat_val->id==$subcatid):   
                  echo "<option value=\"$subcat_val->id\" selected=\"selected\">".stripslashes($subcat_val->name)."</option>";
                  else:
                  echo "<option value=\"$subcat_val->id\"'>".stripslashes($subcat_val->name)."</option>";
                  endif;
               endforeach; 
?>
            </select>
         </div>
<?php
        endforeach; 
?>
</div>


so the code is still on category and subcategory.
and <option> are selected if they correspond to the id stored in the DB.

That is ok..
But when i update infos by submitting the form, Category can be update, be subcat can be update only if we are in the last submenu...

still dont understand what's wrong ...😟

thanks for the help😉
GreyHead 07 Mar, 2009
Hi picsoung,

Hard to test this without building the database tables.

What does the typical form html look like please?

Bob
picsoung 07 Mar, 2009
my original form is
<div class="form_item" >
      <input type='hidden' name='email' value='<?php echo $user->email; ?>' />
      <div class="form_element cf_dropdown">
      <label class="cf_label">Category</label>
         <div id ='category'>
         <select name="objectcat" size="1" id="objectcat" class="cf_inputbox validate-selection" onChange='change_subcat();'>
         <option value="">Please select</option><!--Empty line for ChronoForm required error --!>
<?php //this code permit to use dynamic access to category list
         
      $query= "SELECT * FROM `#__itemcat` ;";
      $db->setQuery($query);
      $result = $db->loadObjectList();
      
      foreach($result as $cle => $val):
        echo "<option value='".$val->id."'>".stripslashes($val->name)."</option>";
      endforeach; 
?>
		</select>
	   </div>
   <div class="clear"> </div>
   </div>
</div>
   
<div class="form_item" >
   <div class="form_element cf_dropdown">
      <label class="cf_label">Subcategory</label>
<?php
         foreach($result as $cle =>$val):
            echo "<div id='".$val->id."' class='select' style='display:none;'>";
?>
            <select id ='objectsubcat' name='objectsubcat' style='width:160px;' size="1">
<?php
               $query= "SELECT * FROM `#__itemsubcat` WHERE `catid`='$val->id';";
               $db->setQuery($query);
               $subcat_result = $db->loadObjectList();
               foreach($subcat_result as $subcat_cle =>$subcat_val):         
                  echo "<option value='".$subcat_val->id."'>".stripslashes($subcat_val->name)."</option>";
               endforeach; 
?>
            </select>
         </div>
<?php
        endforeach; 
?>
</div>
	<div class="clear"> 
	</div>
</div>


but in fact it still doesnt work...
still select the first element of the third menu...

in HTML this is my code (taken from source in firefox)
<div class="form_item" >

      <input type='hidden' name='email' value='nicolas.grenie@gmail.com' />
      <div class="form_element cf_dropdown">
      <label class="cf_label">Category</label>
         <div id ='category'>
         <select name="objectcat" size="1" id="objectcat" class="cf_inputbox validate-selection" onChange='change_subcat();'>
         <option value="">Please select</option><!--Empty line for ChronoForm required error --!>
<option value='1'>Small Electronics,Accessories</option><option value='2'>Keys, Glasses, Personal Items</option><option value='3'>Medical</option>		</select>

	   </div>
   <div class="clear"> </div>
   </div>
</div>
   
<div class="form_item" >
   <div class="form_element cf_dropdown">
      <label class="cf_label">Subcategory</label>
<div id='1' class='select' style='display:none;'>            <select id ='objectsubcat' name='objectsubcat' style='width:160px;' size="1">

<option value='1'>Camera</option><option value='2'>Camera Accessories</option><option value='3'>PDA</option>            </select>
         </div>
<div id='2' class='select' style='display:none;'>            <select id ='objectsubcat' name='objectsubcat' style='width:160px;' size="1">
<option value='4'>Checkbook</option><option value='5'>Jewelry Case/Box</option><option value='6'>Keys</option>            </select>
         </div>
<div id='3' class='select' style='display:none;'>            <select id ='objectsubcat' name='objectsubcat' style='width:160px;' size="1">

<option value='7'>Braces (Knee, Ankle, Wrist)</option><option value='8'>Canes, Crutches, etc.</option><option value='9'>Dental Related</option>            </select>
         </div>
</div>
	<div class="clear"> 
	</div>
</div>


and all the form
<form name="ChronoContact_itemdetails" id="ChronoContact_itemdetails" method="post" action="http://localhost:8888/Joomla_1.5.9/index.php?option=com_chronocontact&task=send&chronoformname=itemdetails" >
		
					
	<div class="form_item" >
		<div class="form_element cf_heading">
			<h1 class="cf_text" id="null">Item details</h1>
		</div>
		<div class="clear"> </div>

	</div>
	<div class="form_item" >	
		<div class="form_element cf_text">
			<span class="cf_text">To setup your EFinder account, please fill in the following information. We encourage you to complete the optional fields below as the more information you provide us, the faster we will be able to return your recovered items to you.</span>
		</div>
		<div class="clear"> </div>
	</div>
	
	<div class="form_item" >

      <input type='hidden' name='email' value='nicolas.grenie@gmail.com' />
      <div class="form_element cf_dropdown">
      <label class="cf_label">Category</label>
         <div id ='category'>
         <select name="objectcat" size="1" id="objectcat" class="cf_inputbox validate-selection" onChange='change_subcat();'>
         <option value="">Please select</option><!--Empty line for ChronoForm required error --!>
<option value='1'>Small Electronics,Accessories</option><option value='2'>Keys, Glasses, Personal Items</option><option value='3'>Medical</option>		</select>

	   </div>
   <div class="clear"> </div>
   </div>
</div>
   
<div class="form_item" >
   <div class="form_element cf_dropdown">
      <label class="cf_label">Subcategory</label>
<div id='1' class='select' style='display:none;'>            <select id ='objectsubcat' name='objectsubcat' style='width:160px;' size="1">

<option value='1'>Camera</option><option value='2'>Camera Accessories</option><option value='3'>PDA</option>            </select>
         </div>
<div id='2' class='select' style='display:none;'>            <select id ='objectsubcat' name='objectsubcat' style='width:160px;' size="1">
<option value='4'>Checkbook</option><option value='5'>Jewelry Case/Box</option><option value='6'>Keys</option>            </select>
         </div>
<div id='3' class='select' style='display:none;'>            <select id ='objectsubcat' name='objectsubcat' style='width:160px;' size="1">

<option value='7'>Braces (Knee, Ankle, Wrist)</option><option value='8'>Canes, Crutches, etc.</option><option value='9'>Dental Related</option>            </select>
         </div>
</div>
	<div class="clear"> 
	</div>
</div>

	<div class="form_item" >
		<div class="form_element cf_dropdown">

			<label class="cf_label">Brand</label>
				<input name="objectbrand" type="text" id="objectbrand" size="30" maxlength="150" class="cf_inputbox">
		</div>
		<div class="clear"> </div>
	</div>
	<div class="form_item" >
		<div class="form_element cf_textbox">
			<label class="cf_label">Model</label>

			<input name="objectmodel" type="text" id="objectmodel" size="30" maxlength="150" class="cf_inputbox required"><a class="tooltiplink" onclick="return false;">
			<img class="tooltipimg" src="/Joomla_1.5.9/components/com_chronocontact/css/images/tooltip.png" border="0"  width="16" height="16"></a>
			<div class="tooltipdiv" >Model :: As iPod, Nokia 2100, PSP</div>
		</div>
		<div class="clear"> </div>
	</div>
	<div class="form_item" >
		<div class="form_element cf_textbox">

			<label class="cf_label">Serial number</label>
			<input name="objectserial" type="text" id="objectserial" size="30" maxlength="150" class="cf_inputbox"><a class="tooltiplink" onclick="return false;">
			<img class="tooltipimg" src="/Joomla_1.5.9/components/com_chronocontact/css/images/tooltip.png" border="0"  width="16" height="16"></a>
			<div class="tooltipdiv" >Serial number :: Optional : serial number of your product</div>
		</div>
		<div class="clear"> </div>
	</div>

	<div class="form_item" >
		<div class="form_element cf_textarea">
			<label class="cf_label">Description</label>
			<textarea name="objectdescription" cols="30" id="objectdescription" rows="3" class="cf_inputbox"></textarea><a class="tooltiplink" onclick="return false;"><img class="tooltipimg" src="/Joomla_1.5.9/components/com_chronocontact/css/images/tooltip.png" border="0"  width="16" height="16"></a>
			<div class="tooltipdiv" >Description :: Describe your item, help us to identify it easily</div>
		</div>
		<div class="clear"> </div>

	</div>
	
	<div class="form_item" >
	<div class="form_element cf_dropdown">
		<label class="cf_label">Where did you buy this tag ?</label>
		<select name="objectshop" size="1" id="objectshop" class="cf_inputbox validate-selection">
		<option value="">Please select</option><!--Empty line for ChronoForm required error --!>
				 	
		<option value="Auchaun">Auchaun</option>

			 	
		<option value="Carrefour">Carrefour</option>
			 	
		<option value="Lawson">Lawson</option>
		</select>
	</div>
	<div class="clear"> 
	</div>
</div>

	
	<div class="form_item" >

		<div class="form_element cf_textbox">
			<label class="cf_label">Cash reward</label>
			<input name="objectcash" type="text" id="objectcash" size="30" maxlength="150" class="cf_inputbox"><a class="tooltiplink" onclick="return false;"><img class="tooltipimg" src="/Joomla_1.5.9/components/com_chronocontact/css/images/tooltip.png" border="0"  width="16" height="16"></a>
			<div class="tooltipdiv" >Cash reward :: If someone found you object, do you wan to give him back cash ?</div>
		</div>
		<div class="clear"> </div>
	</div>

	<div class="form_item" >
		<div class="form_element cf_button">
			<input name="undefined" type="submit" value="Submit details"><input type="reset" value="Reset">
		</div>
		<div class="clear"> </div>
	</div>
	
		<input type="hidden" name="30ab01e3c9cfc19260049972aa8ae5c7" value="1" />		
</form>


with this javascript
function change_subcat()
{
    var cat = $('objectcat');
    var selects = $$('div.select');
    for ( var i = 0; i < selects.length; i++ ) {
        if ( selects[i].id == cat.value ) {
            selects[i].style.display = 'block';
        } else {
            selects[i].style.display = 'none';
        }
    }
}

thanks again for you help🙂
GreyHead 08 Mar, 2009
Hi picsoung,

I can take a better look later but I wonder if the problem is because you are repeating the whole select tag rather than just a block of options?

You could try giving the select an array name and then cleaning any null entries out of the array.

Bob
picsoung 08 Mar, 2009
i find a solution by giving a different name...

so each subcat dropdown has a name like objectsubcat($catid)

that's working and i think is good enough for what i want🙂

thanks again😉
GreyHead 08 Mar, 2009
Hi picsoung,

Well done, sounds like a good solution.

Bob
crisscross 04 Apr, 2009
I am looking for something similar but I have a hard time trying to put everything in this thread together for a working solution.

My setup:
I created one table with chronoforms called 'jos_chronoforms_kommuner'
In this table I have one column kalled 'kommuner' and one called 'lan'
('Kommuner' means municipalities in Swedish and 'lan' correspondens to states.)

I have a couple of hundred 'kommuner', each with a corresponding 'lan' (there is about 20 'lan':s)

In my form I have two drop-down fields, one for 'lan' and one för 'kommun'.
When I choose a 'lan' in the first drop-down I want the drop-down for 'kommun' to populate with the 'kommun'-values that corresponds to that 'lan' and nothing else.

Can somebody point me in the right direction here?
Max_admin 09 Apr, 2009
Hi crisscross,

so you need some dropdown to load new data when the first changed, I'm sure that you will find many answers with code in google!🙂

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
epsdaniel 22 Sep, 2010
Hello!

I would like to get some help in a little problem I can not solve with redirect plugin.

I uses the script to create cat y subcat. The problem I have is all select in subcat have same name. If I change dinamically the name when I uses redirect plugin pass no data to redirect.

How can I do it??

I saw Bob post:

Hi picsoung,
I can take a better look later but I wonder if the problem is because you are repeating the whole select tag rather than just a block of options?
You could try giving the select an array name and then cleaning any null entries out of the array.
Bob



Could you help me to set up a block of options or select an array name??

Here is my subcatcode.
 <div class="form_item" >
       <div class="form_element cf_dropdown">
          <label class="cf_label">Poblaciones</label>
    <?php
             foreach($result as $cle =>$val):
if(($val[0])==$paiss): //añadido
                echo "<div id='".$val[1]."' class='select' style='display:block;'>";
else:
 echo "<div id='".$val[1]."' class='select' style='display:none;'>";
  endif; //añadido
    ?>                <select id ='<?php echo "$val[1]"; ?>' name='<?php echo "$val[1]"; ?>' style='width:160px;'>
    <?php
     $idcle = $val[0];
                   $query= "
                     SELECT * FROM `apobesqui`
                       WHERE `relacion`='$idcle';";
                   $db->setQuery($query);
                   $subcat_result = $db->loadObjectList();
                   foreach($subcat_result as $subcat_cle =>$subcat_val):         
                      echo "<option value='".$subcat_val->ide."'>".stripslashes($subcat_val->estados)."</option>";
                   endforeach;
    ?>
                </select>
             </div>
    <?php
            endforeach;
    ?>
    </div>
GreyHead 25 Sep, 2010
Hi epsdaniel,

I'm not clear what the problem is here. The code looks OK - where are you using it?

Bob
epsdaniel 26 Sep, 2010
Hello Bob,

Sorry for my english. I try to explain.

I use redirect plugin. When I am setting it up, appears differents field to apply in General tab. In subcat I can not catch the correct value of the option selected. Subcats are a group of select with differents options.

3 cases I have tried to name subcategory field in differents select.

- If I use a static name (select name='subcategory') in redirect plugin appear "subcategory" (in field name tabs general - 'subcategory' field). Output:
<div id='Pirineo Aragones' class='select' style='display:none;'> <select id ='Pirineo Aragones' name='subcategory' style='width:160px;'> <option> xxx </option> </select> </div>

<div id='Sierra Nevada' class='select' style='display:none;'> <select id ='Sierra Nevada' name='subcategory' style='width:160px;'> <option> xxx </option> </select> </div>

All groups of subcategory will have same name name='subcategory' so when I submit de form the redirect plugin do not takes the correct option value in selected dropdown (style='display:block;). It takes the last one value even when this subcats is not the selected one. display:none.

- If I use name dinamically (name='<?php echo "$val[1]"") just to have differents select names value. Field does not appear in redirect plugin. So can not assign any field name and does not takes into account when submitting form.

- If I use mix statictext + dinamically then appears only anytext and value is null (no value). So does not work. Example
name='Estacion <?php echo "$val[1]"". In general tabs of redirect plugin can see something like 'estacion (with no end ') and when submitting blank value is passed to url.

I need a way to build select names in a way that I'm able to catch the select name field, value of the option in the selected subcats and pass to redirects plugin (which convert in a url parameter).

I have an estructure like that. Is Cat - Option 2 is selected Subcat 2 appear with Options. If Option 2 is selected only this value should be sent to redirect plugin (value=5).

Cat
Option 1
Option 2

Subcat name=1 (Cat 1)
Option 1 value 2
Option 2 value 3

Subcat name=2 (Cat 2)
Option 1 value 4
Option 2 value 5

Hope you can understands.

Thanks so much for your help.

Dani
GreyHead 26 Sep, 2010
Hi epsdaniel,

Ah! OK. I think you need to disable the un-used selects, not just hide them.
<div id='Pirineo Aragones' class='select' style='display:none;'>
  <select id ='Pirineo Aragones' name='subcategory' style='width:160px;' disabled='disabled' >
    <option> xxx </option>
  </select>
</div>


Bob
epsdaniel 28 Sep, 2010
Thanks so much Bob.

Everything works now like a charm.

Dani
GreyHead 07 Oct, 2010
Hi garvard,

I'm afraid that you will need to beg, borrow or learn some coding skills to work with ChronoForms at more than the drag and drop level.

Here's the code for the US State drop-down updated to use Joomla!1.5 code:
<?php
if ( !$mainframe->isSite() ) { return; }
$USStateArray = Array(
'AK' => 'Alaska',
'AL' => 'Alabama',
'AR' => 'Arkansas',
'AZ' => 'Arizona',
'CA' => 'California',
'CO' => 'Colorado',
'CT' => 'Connecticut',
'DC' => 'District of Columbia',
'DE' => 'Delaware',
'FL' => 'Florida',
'GA' => 'Georgia',
'HI' => 'Hawaii',
'IA' => 'Iowa',
'ID' => 'Idaho',
'IL' => 'Illinois',
'IN' => 'Indiana',
'KS' => 'Kansas',
'KY' => 'Kentucky',
'LA' => 'Louisiana',
'MA' => 'Massachusetts',
'MD' => 'Maryland',
'ME' => 'Maine',
'MI' => 'Michigan',
'MN' => 'Minnesota',
'MO' => 'Missouri',
'MS' => 'Mississippi',
'MT' => 'Montana',
'NC' => 'North Carolina',
'MD' => 'North Dakota',
'ME' => 'Nebraska',
'NH' => 'New Hampshire',
'NJ' => 'New Jersey',
'NM' => 'New Mexico',
'NV' => 'Nevada',
'NY' => 'New York',
'OH' => 'Ohio',
'OK' => 'Oklahoma',
'OR' => 'Oregon',
'PA' => 'Pennsylvania',
'PR' => 'Puerto Rico',
'RI' => 'Rhode Island',
'SC' => 'South Carolina',
'SD' => 'South Dakota',
'TN' => 'Tennessee',
'TX' => 'Texas',
'UT' => 'Utah',
'VA' => 'Virginia',
'VT' => 'Vermont',
'WA' => 'Washington',
'WI' => 'Wisconsin',
'WV' => 'West Virginia',
'WY' => 'Wyoming' );
$state = JRequest::getString('state', '', 'post');
$options = array();
foreach ( $USStateArray as $abb => $name ) {
  $options[] = JHTML::_('select.option', $abb, $name);
}
$select_state = JHTML::_('select.genericlist', $options, 'state[]', 'size="1"', 'value', 'text', $state);
?>
<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Click Me to Edit</label>
    <?php echo $select_state; ?>
  </div>
  <div class="cfclear"> </div>
</div>


Bob
Shamray 20 Apr, 2011
Great, it has helped me to sort it out also!
This topic is locked and no more replies can be posted.