A JM Posted June 19, 2009 Share Posted June 19, 2009 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>... Quote Link to comment https://forums.phpfreaks.com/topic/162899-masterdetail-how-to-populate-an-option/ Share on other sites More sharing options...
joel24 Posted June 19, 2009 Share Posted June 19, 2009 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> } Quote Link to comment https://forums.phpfreaks.com/topic/162899-masterdetail-how-to-populate-an-option/#findComment-859530 Share on other sites More sharing options...
A JM Posted June 19, 2009 Author Share Posted June 19, 2009 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, Quote Link to comment https://forums.phpfreaks.com/topic/162899-masterdetail-how-to-populate-an-option/#findComment-859801 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.