Welcome Guest, Not a member yet? Register   Sign In
Clearing a select box after form submit.
#1

Code:
<select class="form-control" id="project_type" name="project_type">
<option value="">Select..</option>
<?php foreach ($project_types as $value): ?>
<option value="<?= $value['PROJTYP_CODE'] ?>" <?= set_select('project_type', $value['PROJTYP_CODE']); ?>><?= $value['PROJTYP_CODE'].' - '.$value['PROJTYP_DSC'] ?></option>
<?php endforeach ?>
</select>

I have a select box that I am dynamically creating options for with php and repopulating the input with CI's set_select().

Everything works as expected but when I try to clear the form, the repopulated option acts as the selectedIndex ( as it should ) and I can't reset the input to the top option. I've tried a couple solutions with jQuery but had no luck.

Has any one else ran into this issue? if so how did you handle it?
Reply
#2

In jQuery, you would just use $('#project_type').prop('selectedIndex', 0);
Reply
#3

(02-12-2015, 06:46 AM)BrandenM Wrote: when I try to clear the form, the repopulated option acts as the selectedIndex ( as it should ) and I can't reset the input to the top option.
I think I had a problem similar to that, and I solved it this way.
PHP Code:
   <select name="gift_list]">
 
     <option value="0" <?= set_select('gift_list''0'?>>Select...</option> 
Basically, I treated the top option as a valid selection with value zero. If the user doesn't make a different selection (one that has a non-zero value), I can catch that during validation.
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB