Jump to content

Master/Detail - how to populate an option?


A JM

Recommended Posts

I'm using a Master/Detail scenario and my Detail page has a State field that I am trying to populate but not having any luck - can someone give me a hand with this?

 

Selected should be the default but its not working...

 

<select name="clnt_state" id="clnt_state" tabindex="8" class="form-inputitem" selected"<?php echo htmlentities($row_rstocdetail['clnt_state'], ENT_COMPAT, 'utf-8'); ?>">
                            	<option value=""></option>
                                <option value="AL">AL</option>
                                <option value="AK">AK</option>
                                <option value="AZ">AZ</option>
                                <option value="AR">AR</option>
                                <option value="CA">CA</option>
                                <option value="CO">CO</option>
                                <option value="CT">CT</option>
                                <option value="DE">DE</option>
                                <option value="DC">DC</option>
                                <option value="FL">FL</option>
                                <option value="GA">GA</option>
                                <option value="HI">HI</option>...

Link to comment
https://forums.phpfreaks.com/topic/162899-masterdetail-how-to-populate-an-option/
Share on other sites

as far as I know you're meant to define the selected option in the option tag...

i.e.

<select name="clnt_state" id="clnt_state" tabindex="8" class="form-inputitem">
                               <option value="" selected></option>
                                <option value="AL">AL</option>
</select>

 

how is each individual state <option> getting written?

manually or from an array...?

 

i'd suggest putting the states into an array,

then doing a foreach loop to list them all i.e.

 

foreach ($states as $s) {

 

if ($row_rstocdetail['clnt_state'] == $s) {

$isSelected = "selected";

} else {

$isSelected = "";

}

 

echo '<option '.$isSelected.' value="'.$s.'">'.$s.'</option>

}

Hey joel24 nice to see you again.

 

After re-reading my post I realize that I left out some important info. like I'm trying to set the default value from a recordset.

 

So, I have a recordset that I am reading and using and I need to populate the state field onmy form which is essentially an EDIT form for the user to change the state if necessary.

 

Sorry about that.

 

A JM,

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.