PDA

View Full Version : how to make select menu and/or list sticky without javascript?


nanny
06-14-2007, 01:50 AM
Hi I am using 3 select menus that are not related for drop downs as in the tutorial.
I have them dynamic from a recordset in my form as the list is extensive.
I don't want to use the for each method and I understand it is an array.
So to have them sticky on resubmit on error, how do I go about this?
Do I put in my error checking above the doc type:
e.g.

$industry = $_POST['industry'];
$_POST['industry'] = array();
if (empty($_POST['industry'])){
$error['industry'] = 'Please select your industry';
}


How do you place the array() info into the select menu?
OH sorry, it isn't a multiple, I will have one of those later.....

davidj
06-14-2007, 06:58 AM
so you want to retain and highlight the option in the select dropdown field?

if yes post the code of the select dropdown

nanny
06-14-2007, 08:36 AM
Yes thank you:
<select name="industry">
<option value="">Select an Industry</option>
<?php do { ?>
<option value="<?php echo $rowindust['classify']; ?>"><?php echo $rowindust['classify']; ?></option>
<?php }while ($rowindust = mysql_fetch_array($result)); ?>
</select>

davidj
06-14-2007, 11:06 AM
check out this bit...

note the $_POST var. Change the name of that to whatever you call yours or substitute it with a variable.


<?php if(!(strcmp($rowindust['classify'], $_POST['industry']))){echo "selected"; }?>


example...

<select name="industry">
<option value="">Select an Industry</option>
<?php do { ?>
<option value="<?php echo $rowindust['classify']; ?>" <?php if(!(strcmp($rowindust['classify'], $_POST['industry']))){echo "selected"; }?> ><?php echo $rowindust['classify']; ?></option>
<?php }while ($rowindust = mysql_fetch_array($result)); ?>
</select>

nanny
06-15-2007, 12:55 AM
Hi David I am losing the dynamic menu and in the browser it only says selected. That's it.
Would it be that the mysql table doesn't have an integer id???
example:

CREATE TABLE categorytype
(
categorytype VARCHAR(255) NULL,
PRIMARY KEY (categorytype)
);

I will change it and try it.

nanny
06-15-2007, 02:14 AM
No it doesn't work, I changed all of my database to suit, took a little while.
e.g.

CREATE TABLE categorytype
(
classtypeid INT(11) PRIMARY KEY AUTO_INCREMENT NOT NULL,
categorytype VARCHAR(255) NULL
);

It still won't highlight or keep the selection selected.

nanny
06-15-2007, 02:57 AM
I am going to drive you insane........

I got it working - after I turned Dreamweaver off and on again, it worked a treat.
I often find that I need to invoke the mysql database to refresh the changes.
Can I ask though, what is the difference between the code:

} while ($row_indust = mysql_fetch_assoc($indust));
$rows = mysql_num_rows($indust);
if($rows > 0) {
mysql_data_seek($indust, 0);
$row_indust = mysql_fetch_assoc($indust);
}

and simply having:

} while ($row_indust = mysql_fetch_assoc($indust));

Is one better than the other???? or is the first just a double up.

Thanks so much for your help. I would never have got there........especially with strcmp.
Now maybe it might work with checkboxes as well...........mmmmmmmm
something new to try.