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
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>

}

Link to comment
Share on other sites

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,

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.