CodeIgniter Forums
dropdown list clears after press submit button - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: dropdown list clears after press submit button (/showthread.php?tid=70973)



dropdown list clears after press submit button - kvanaraj - 06-23-2018

I am new to the codeigniter. i m doing one application there are two dropdown list and one sumbit button. based on dropdown value list's are displayed. every think is ok. i got the value to the controller .post is working well. 

but the dropdown list clears after submit button presses. why?


RE: dropdown list clears after press submit button - Pertti - 06-24-2018

In the part you generate options, you also need to set the  selected option.

You can do this by checking the returned post variable with select tag name attribute with looped through city codes you use to set option return values:

PHP Code:
<select class="form-control required" id="sel_bran" name="branch">
<
option>-- Select Branch --</option>
<?
php
    foreach
($getbranch as $city) {
 
       echo "<option value='".$city['brcode']."'"
 
           .($this->input->post('branch') == $city['brcode'] ? ' selected' ''            
            
.">".$city['degshort']. " :".$city['brname']." [ ".$city['degmode']." ] "."</option>";
 
   }
?>
</select> 

You can also use CodeIgniter built in form helper to generate HTML for select dropdowns.


RE: dropdown list clears after press submit button - kvanaraj - 06-24-2018

no changes.
my form look like
<?php $this->load->helper("form"); ?>
<?php echo form_open('user/addtest'); ?>
<?php $attributes = array('class' => 'form-inline reset-margin', 'id' => 'myform'); ?>
I st drop down list
II nd dropdown list
<?php $data_submit = array('name' => 'submit', 'value' => 'Go'); ?>
<?php echo form_submit($data_submit); ?>
<?php echo form_close(); ?>

once this form close i can able to post ,my data pass to the controller name called "add_attend" .

<?php echo form_open('User/add_attend'); ?>

any suggestion


RE: dropdown list clears after press submit button - Pertti - 06-25-2018

The problem would still be with how you generate the dropdowns, not with how you do the rest.

Also, you can use the helpful php tags to format your code nicer and make it easier to read on the forum Wink


RE: dropdown list clears after press submit button - kvanaraj - 06-25-2018

i attached my complete code


RE: dropdown list clears after press submit button - Pertti - 06-25-2018

(06-25-2018, 01:30 AM)kvanaraj Wrote: i attached my complete code

Looks like you have two forms in that file? One starts on line 28 and ends on line 72, and one with no obvious start point but it's closed on line 129.

In HTML you can only submit one form element at the time, and only elements inside that <form> will be submitted. You can't have form elements inside another form element, and form has to start and close on the same level, so you can't start form inside a table cell for example then close it on different table cell, you have to move it out to wrap the whole table.

As a next step, if I was you, I'd debug the POST I get between pages and first make sure all the info I expect to be sent back from the browser actually is.


RE: dropdown list clears after press submit button - kvanaraj - 06-25-2018

screen shot of my page is attached. kindly help me. what wrong with my coding and also my screenshot of output