i am trying to get content inside a div using ajax, on the php page that am accessing using ajax, i want to fill dropdown options using another query but it just closes the select tag before the options.
<select class="form-control data" data-t="integer" name='role' required/>
<option value="">--Select--</option>
<?php
foreach($con -> query("select id,name,permissions from role") as $role){
?>
<option value="<?php echo $role['id']; ?>"><?php echo $role['name']; ?></option>
<?php
}
?>
</select>
But here is what i get inside the div
<select class="form-control data" data-t="integer" name="role"
required=""></select>
<option value='1' >option1</option>
<option value='2' >option2</option>
<option value='3' >option3</option>
please remove forward / at the end of opening select tag as below:
<select class="form-control data" data-t="integer" name='role' required>
<option value="">--Select--</option>
<?php
foreach($con -> query("select id,name,permissions from role") as $role){
?>
<option value="<?php echo $role['id']; ?>"><?php echo $role['name']; ?></option>
<?php
}
?>
</select>
Related
I want to make a dropdown list based on options that are obtained from an MySQL database. At this moment my code looks like this:
<?php
if ($resultCheck12 > 0) {
while ($row = mysqli_fetch_assoc($result12)) { ?>
<select name="storage_location[]" required>
<option value=""></option>
<option value="<?php echo $row['id']; ?>"><?php echo $row['storage_name']; ?></option>
</select>
<?php } } ?>
And this code should produce a result that looks like this if it was unsystematically coded:
<select name="sample_group[]" class="sample_group" required>
<option value=""></option>
<option value="water">Water</option>
<option value="pharmaceutical">Pharmaceutical</option>
<option value="food">Food</option>
<option value="food">Swabs</option>
<option value="custom">Custom</option>
</select>
However the results produce something like this:
<select name="sample_group[]" class="sample_group" required>
<option value=""></option>
<option value="water">Water</option>
</select>
<select name="sample_group[]" class="sample_group" required>
<option value=""></option>
<option value="pharmaceutical">Pharmaceutical</option>
</select>
<select name="sample_group[]" class="sample_group" required>
<option value=""></option>
<option value="food">Food</option>
</select>
<select name="sample_group[]" class="sample_group" required>
<option value=""></option>
<option value="swabs">Swabs</option>
</select>
<select name="sample_group[]" class="sample_group" required>
<option value=""></option>
<option value="custom">Custom</option>
</select>
Instead of producing a single dropdown list it makes one for each variable from the MySQL database.
Any ideas how to resolve this issue?
<?php
if ($resultCheck12 > 0) { ?>
<select name="storage_location[]" required>
<option value=""></option>
<?php while ($row = mysqli_fetch_assoc($result12)) { ?>
<option value="<?php echo $row['id']; ?>"><?php echo $row['storage_name']; ?></option>
<?php } ?>
</select>
<?php } ?>
The select tag should be outside the while loop
You are using select tag inside while loop that's why it is repeating it multiple times.
<?php if ($resultCheck12 > 0) { ?>
<select name="storage_location[]" required>
<option value=""></option>
<?php while ($row = mysqli_fetch_assoc($result12)) { ?>
<option value="<?php echo $row['id']; ?>"><?php echo $row['storage_name']; ?></option>
<?php } ?>
</select>
<?php } ?>
I have a country dropdown
<select name="country" class="form-control"/>
<option>Select a Country</option>
<?php foreach($country_list as $country) :?>
<option value="<?php echo $account_result->Country;?>"
<?php
if($country->id==$account_result->Country)
{echo 'selected="selected"';};?>>
<?php echo $country->name; ?></option>
<?php endforeach; ?>
</select>
but while updating I am getting only selected value id it's not changing.
You setting same value to all options change this line:
<option value="<?php echo $account_result->Country;?>"
to:
<option value="<?php echo $country->id;?>"
Try below
You have added wrong value in option
<select name="country" class="form-control"/>
<option>Select a Country</option>
<?php foreach($country_list as $country) :?>
<option value="<?php echo $country->id;?>"
<?php
if($country->id==$account_result->Country)
{echo 'selected="selected"';};?>>
<?php echo $country->name; ?></option>
<?php endforeach; ?>
</select>
<?php echo $country->id == $account_result->Country ?"selected":"";?>
your $country->id and $account_result->Country should be same value example
ex: 44=44
then it will be get selected in default page load.
and you have to set the option value as like this.
<option value="<?php echo $country->id;?>"
how do i get the select tag value, i am using the syntax below but not working.
Controller
'role' => $this->input->post('rol'));
View
these are the options in my select tag
<select name="rol">
<option value="Employee">Employee</option>
<option value="HR">HR</option>
<option value="Student">Student</option>
</select>
$role = $this->input->post("rol");
Just try it to post like below:
<form action="your_controller_action" method="POST">
<select name="rol" id="pos_select" class="form_input">
<option value="Employee">Employee </option>
<option value="HR">HR</option>
<option value="Student">Student</option>
</select>
<input type="submit" name="submit" value="Post it">
</form>
Then in your controller:
public function youControllerAction() {
if( $this->input->post) {
echo $this->input->post("rol");
}
}
You will get the selected option value.
how did you write your selection dropdown list!did you take it as i posted below?
<select name="rol" id="pos_select" class="form_input">
<option value="Employee">Employee </option>
<option value="HR">HR</option>
<option value="Student">Student</option>
</select>
$role = $this->input->post("rol");
put this code in view. Only you have to call controller function in action. In this example I am getting option values from database
<form method="post" action="<?php echo base_url()."main/project_filter_skills"; ?>">
<select class="demo-default " id="skilltags" name="skilltags[]" data-placeholder="Choose skills">
<option value="">Choose skills</option>
<?php foreach ($all_skill_tags as $skilltags) { ?>
<option value="<?php echo $skilltags->secondCat_id;?>">
<?php echo $skilltags->secondCat_title;?>
</option>
<?php } ?>
</select>
</form>
now put this in modal or controller to get the vlaue
$skilltags= $this->input->post('skilltags');
I am new in programming i just want that the value i choose in drop downs must retain selected when i click the search button ...
here is the code
<select name="campaigntype" id="campaigntype" class="text dropDownNewsletter" onchange="GetCampaigns()" style="float:left; margin-right:15px;">
<option value="">Select Campaign</option>
<option value="1" >OB Campaign</option>
<option value="2">Casbo Campaign</option>
</select>
<div id="selected_campaigns" style="float:left">
<select name="campaignid" id="campaignid" class="text dropDownNewsletter">
<option value="">Select Campaign</option>
<?php foreach($campaigns as $key=>$row){?>
<option value="<?php echo $row['id'];?>" <?php if( $row['id'] == $campaign_id) {?> selected="selected" <?php } ?> ><?php echo $row['id'].'-'.$row['title'];?></option>
<?php }?>
</select>
I'm a newbie for codeigniter. I'm stuck at a problem, that my form is not posting values, I dont know why.
Current site works fine on local server and my testing server. As I transferred complete site on clients server, this problem occurred.
I have checked, htaccess is enabled. I'm also pasting my view, and controller.
Please help me
VIEW
<form name="form1" method="post" action="index.php/search/make_url">
<div class="search_form">
<label for="shop"></label>
<select name="category" id="select">
<option value="0">-- Shops / Webshops --</option>
<?php
$cats=load_categories();
foreach($cats as $cat){
?>
<option value="<?php echo $cat->cat_name_en."---".$cat->catId;?>"><?php echo $cat->cat_name_en;?></option>
<?php }?>
</select>
<select name="product">
<option value="0">-- <?php echo $this->lang->line("text_select_prod");?> --</option>
<?php
$cats=load_products();
foreach($cats as $cat){
?>
<option value="<?php echo $cat->p_name_en;?>---<?php echo $cat->pId;?>"><?php echo $cat->p_name_en;?></option>
<?php }?>
</select>
<label for="select2"></label>
<select name="brand" id="brand">
<option value="0">-- <?php echo $this->lang->line("text_select_chose_brand");?> --</option>
<?php
$cats=load_brands();
foreach($cats as $cat){
?>
<option value="<?php echo $cat->brand_name_en;?>---<?php echo $cat->brandId;?>"><?php echo $cat->brand_name_en;?></option>
<?php }?>
</select>
<label for="select3"></label>
<select name="country" id="country" onchange="getCity(this.value);">
<option value="0">-- <?php echo $this->lang->line("text_select_country");?> ---</option>
<?php
$cats=load_country();
foreach($cats as $cat){
?>
<option value="<?php echo $cat->cn_name;?>---<?php echo $cat->cnId;?>"><?php echo $cat->cn_name;?></option>
<?php }?>
</select>
<label for="select4"></label>
<div id="cityBlock">
<select name="city" id="city">
<option value="0">-- <?php echo $this->lang->line("text_select_city");?> --</option>
</select>
</div>
<input type="submit" name="btn" value="<?php echo $this->lang->line("text_btn_submit");?>">
</div>
</form>
CONTROLLER
public function make_url()
{
$url=$this->uri->assoc_to_uri($_POST);
redirect(base_url()."index.php/search/for/". $url);
}
Thanks in advance
Check out this way:
<?=form_open('immovable/personal/add_personal');?>
<input type='text' id='fname' name='fname' required />
<input type='text' id='lname' name='lname' required />
<input type='submit' value='Submit' />
<?=form_close()?>
I solved this problem later. Problem was base tag used in Head tag. I simply removed it, and website was functional.
$config[suffix] is the solution for the above problem
Refer this link for better explanation