I have a page that selects value from different tables, when I select a class corresponding divisions are displayed (I used javascript) but when I click the view button I want all the values selected to be displayed. I am done with all the value including class, but corresponding division doesnot get displayed. since I am not much eficient in php, cant find out how, plz do help.
Here is my code that displays class in the textbox when selected.
<div class="field">
Class:
<div id="combo" style="width:20px;">
<select name="class" id="class" onChange="getDivision(this.value)">
<option value="">Select</option>
<?php
$select3="select * from ".TABLE_CLASS."";
$res=mysql_query($select3);
while($row=mysql_fetch_array($res)) {
?>
<option value="<?php echo $row['ID']?>" <?php if($row['ID']==#$_POST['class']){ ?> selected="selected"<?php }?>><?php echo $row['class'];?></option>
<?php
}
?>
</select>
</div>
</div>
<!--<div id="aa"></div>-->
<div class="field">
Division:
<div id="combo" style="width:20px;">
<select name="division" id="division" >
<!--<option value="">Select</option>-->
<option value="<?php echo $row['division'];?>"></option>
</select>
</div>
<!--<input type="text" name="a" id="a">-->
</div>
</div> <!-- /login-fields -->
<option value="<?php echo $row['division'];?>"></option>
You got nothing in those line between option tag. Put some thing there i am using $row['division']. just to show you that you are missing that
<option value="<?php echo $row['division'];?>"><?php echo $row['division'];?></option>
Related
So when i press submit every other field with input is printed, but selected option tag isnt printed in html, since option values are stored in an array..
select forms :
<div class="form-group">
<select class="form-control" name="from">
<option selected disabled>--Isvykimo vieta</option>
<?php foreach($cities as $city):?>
<option value='' style="color:black;"><?=$city;?></option>
<?php endforeach;?>
</select>
</div>
<div class="form-group">
<select class="form-control" name="destination">
<option selected disabled>--Keliones tikslas</option>
<?php foreach($destinations as $destination):?>
<option value='' style="color:black;"><?=$destination;?></option>
<?php endforeach;?>
</select>
</div>
and when i try to post
<div class="ticket">
<?php if(isset($_POST['send'])) ?>
<div class="ticketInfo">
<h5><?php echo htmlentities($_POST['names']);?> <?php echo htmlentities($_POST['lastName']);?></h5>
<p>From: <?= $_POST['from'];?> To:<?= $_POST['destination'];?></p>
</div>
</div>
from to is just left blank
<option value="<?=$city;?>" style="color:black;"><?=$city;?></option>
your value of input was empty, try like this please
I have the following code, I am trying to make it so that the selected field displays on a php page when I return that hit the submit button, I'm doing this below.
<form action="welcome.php" method="post">
<div class="form-group">
<select class="form-control" id="inputState" style="width: 100%">
<option selected>
Choose...
</option>
<option name="account" value="1">
Minecraft Account
</option>
<option name="cape" value="2">
Minecraft Cape
</option>
</select>
</div>
<input type="submit">
</form>
this is my php echo code, but it does not work
<?php echo $_POST["account"]; ?>
<?php echo $_POST["cape"]; ?>
Set name to your select control
<select name="inputState" class="form-control"
Then you can get the "value" of selected item
<?php echo $_POST["inputState"]; ?>
When I select the all data of a product by it's product_id. and load product data in a form for an update. but here I cannot set selected drop-down list value in this case.
here, is my view
<form action="<?php //echo base_url().'admin_product/pro_update/'?>" method="post" class="form-horizontal">
<div class="control-group">
<label class="control-label">Title :</label>
<div class="controls">
<input type="text" class="span5 m-wrap" placeholder="Product title" name="title" value="<?php echo $item[0]['p_title']?>" />
<h6 style="color:red"><?php echo form_error('title')?></h6>
</div>
</div>
<div class="control-group">
<label class="control-label">Category :</label>
<div class="controls">
<select name="cat" id="cat">
<option value="">--Select Category--</option>
<?php foreach($cat as $c):?>
<option value="<?php echo $c->cat_id?>"><?php echo $c->cat_name;?>//selected set value here</option>
<?php endforeach;?>
</select>
<h6 style="color:red"><?php echo form_error('cat')?></h6>
</div>
</div>
here is my controller code,
public function pro_edit($id)
{
$p['item']=$this->ap->product_update($id);
$p['cat']=$this->ap->up_cat();
$p['color']=$this->ap->up_color();
$this->load->view('layouts/header',$p);
$this->load->view('admin/product_update',$p);
$this->load->view('layouts/footer',$p);
}
and model code,
public function product_update($id)
{
$this->db->select('p_title,p_description,p_category,p_stock_quantity,p_pprice,p_sprice,p_size_variant,cat_name,v_color,v_size,p_id');
$this->db->from('tbl_product');
$this->db->join('tbl_category','tbl_product.p_category=tbl_category.cat_id');
$this->db->join('tbl_variant','tbl_product.p_color_variant=tbl_variant.v_id');
$this->db->where('p_id',$id);
$query=$this->db->get();
return $query->result_array();
}
Assumptions
p_category is your category id
Code
<select name="cat" id="cat">
<option value="">--Select Category--</option>
<?php
foreach($cat as $c):?>
<option value="<?php echo $c->cat_id?>" <?php echo ($item[0]['p_category'] == $c->cat_id) ? 'selected' : '' ?>>
<?php echo $c->cat_name;?>
</option>
<?php
endforeach;
?>
</select>
Explain
Q - What this if do in above <?php echo ($item[0]['p_category'] == $c->cat_id) ? 'selected' : '' ?>
A - Assume $item[0]['p_category'] has value 2 so when ever $c->cat_id equesl to that value its print selected keyword
Ex:
<select>
<option value="1">aa</option>
<option value="2" selected>bb</option>
<option value="3">cc</option>
<option value="4">dd</option>
</select>
I am trying to get user selection from php form but instead of name I am getting id of elements. instead of ids I want to get names. Please help
here is the url
http://efinancec.com/d/drop4/index.php
and here is the code
<form action="../form/form1.php" method="post" enctype="multipart/form-data">
<div class="frmDronpDown">
<div class="row">
<label>Training:</label><br/>
<select name="training" id="training-list" class="demoInputBox" onChange="getCourse(this.value);">
<option value="">Select Training</option>
<?php
foreach($results as $training) {
?>
<option value="<?php echo $training["id"]; ?>"><?php echo $training["training"]; ?></option>
<?php
}
?>
</select>
</div>
<div class="row">
<label>Course:</label><br/>
<select name="course" id="course-list" class="demoInputBox" onChange="getCountry(this.value);">
<option value="">Select Course</option>
</select>
</div>
<div class="row">
<label>Country:</label><br/>
<select name="country" id="country-list" class="demoInputBox" onChange="getCity(this.value);">
<option value="">Select Country</option>
</select>
</div>
<div class="row">
<label>City:</label><br/>
<select name="city" id="city-list" class="demoInputBox" onChange="getDates(this.value);">
<option value="">Select City</option>
</select>
</div>
<div class="row">
<label>Dates:</label><br/>
<select name="dates" id="dates-list" class="demoInputBox" onChange="getPrice(this.value);">
<option value="">Select Dates</option>
</select>
</div>
<div class="row">
<label>Online Onsite Price:</label><br/>
<select name="price" id="price-list" class="demoInputBox">
<option value="">Select Online or Onsite</option>
</select>
</div>
<input id="submit" name="submit" type="submit" value="Submit">
</form>
and this is how I am getting the values from sql database
<?php
require_once("dbcontroller.php");
$db_handle = new DBController();
if(!empty($_POST["training_id"])) {
$query ="SELECT * FROM course WHERE training_id = '" . $_POST["training_id"] . "'";
$results = $db_handle->runQuery($query);
?>
<option value="">Select Course</option>
<?php
foreach($results as $course) {
?>
<option value="<?php echo $course["id"]; ?>"><?php echo $course["course"]; ?></option>
<?php
}
}
?>
Change this line:
onChange="getCourse(this.value);">
To this :
onChange="getCourse(this.text);">
You are passing id of the course as the value of dropdown and calling that value which is fine but you need to call the text of select option to get the course name.
I changed this.value to this.text as suggested and created the new page and it stoped working at all now it is not pulling the records from database except the first one. Here is the link
http://efinancec.com/d/drop4/index1.php
where as my earlier page is still working fine.
http://efinancec.com/d/drop4/index.php
I think I could not convey my problem earlier. My depended dropdown is working fine but when a user submits the form in the email I receive the ids instead of name. Thats the problem.
For example I myself made some selections on index.php and submitted form Here is the email I got
training: 1
course : 101
country: 1001
city: 5005
Basically I am getting the the respective ids instead of name.
I'am looking for a hide show script based on parentCatId and catId!
This is the div i try to hide and or show! div class="item-post-lot-area"
<div class="item-post-lot-area">
<label for="s_lotsize">
<?php _e('Lot Area', 'ctg_housing'); ?>
</label>
<div class="row collapse prefix-radius">
<div class="item-post-area-sign columns">
<span class="prefix"><?php echo osc_get_preference('metric','ctg_housing_theme'); ?></span>
</div>
<div class="item-post-area-number columns">
<input type="number" name="s_lotsize" id="s_lotsize" value="<?php if(isset($housingOut['s_lotsize'])) { echo $housingOut['s_lotsize'];} ?>" >
</div>
</div>
</div>
what i try!
item-post-lot-area field will all time show when loading the page! And will hide when selected the following parentCatId and catId
<option value="28">Vacation</option>
<select id="catId" name="catId" class="valid">
<option value="28">Select Subcategory</option>
<option value="29">Pension House</option>
<option value="30">Inn / Motel</option>
<option value="31">Hotel & Resort</option>
</option>
</select>
<select id="catId" name="catId" class="valid">
<option value="32">Select Subcategory</option>
<option value="33">Space</option>
<option value="34">Office</option>
<option value="35">BPO</option>
<option value="36">Economic</option>
</select>
Can someone explain me how to do this?
Thanks
You're probably looking along the lines of using .on("change") to run when the select element is changed. You can then check which value (if need be) has been selected, and then use $(".item-post-lot-area").hide() to hide the div.
$("#catId").on("change", function(){
$(".item-post-lot-area").hide();
});