javascript - Codeigniter: The default value of a text input field if data is not returned from the controller -


i have text input populated values database passed controller. how have done it:

<input type="text" class="form-control" id="groupname" name="groupname" disabled value="<?php foreach ($result $r) {     echo $r->group_name; };?>"/> <br>` 

this code should executed once search button clicked , working well. problem is, every time load view,this input field loaded meaning code executed , since have not searched anything, giving me error. how can set default value of input box null/empty default or if no value returned controller.

am newbie. appreciated.

you can check whether search performed or not checking array

<input type="text" class="form-control" id="groupname" name="groupname" disabled value="<?php if(isset($result) && !empty($result)){ foreach ($result $r) {     echo $r->group_name; } };?>"/> <br>` 

explanation

i use if(isset($result) && !empty($result)){ condition in have checked if search happens means there $result set , there must in $result. if refresh page there no value in $result not process foreach loop.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -