I have one dropdown with a foreach loop which will pass to model using post method.
<div class="form-group" ">
<select class="form-control" id="rel" name="rl[][rel]" >
<option></option>
<?php
foreach ($relationship as $row) {
?>
<option value="<?php echo $row->relID; ?>"><?php echo $row->relCat; ?></option>
<?php
}
?>
</select>
</div>
and in the model it is getting the proper values using post method. As
$rel = $_POST['rel'];
Here the problem is when the user select one option ,I want to get two values like
"<?php echo $row->relID; ?>" and "<?php echo $row->relCatID; ?>"
like
$rel = $_POST['rel']; //this for the $row ->relID
$relcat = $_POST['relcat'];//this for the $row ->relCatID
I want to get both from one selection without adding any visble dropdown or element..
Try bellow code with ajax call
In Javascript code get value
var name = $('#rel option:selected').attr('data-cat_id');
var id = $('#rel').val();
<div class="form-group" >
<select class="form-control" id="rel" name="rl[][rel]" >
<option></option>
<?php foreach ($relationship as $row) { ?>
<option value="<?php echo $row->relID; ?>" data-cat_id="<?php echo $row->relCatID; ?>"><?php echo $row->relCat; ?></option>
<?php } ?>
</select>
</div>
Related
The following is my HTML code
<div class="col-md-6">
<label for="martial_status">Martial Status</label>
<select name="martial_status" id="martial_status" class="form-control" value="<?php echo set_value('martial_status'); ?>">
<option value="">Select Martial Status</option>
<?php foreach ($martial_status as $status) { ?>
<option value="<?php echo $status['id'] ?>"><?php echo $status['status_name'] ?></option>
<?php } ?>
</select>
Even though i have used the form_validation in controller side, the value is not getting set in drop down once the form fails submitting. How to set the previous value selected in drop down on form failure. Where am I going wrong.
You cannot set the value straightly to select tag. You need to set the selected attribute to option tag which you want it to be get selected. Just like it below....
<div class="col-md-6">
<label for="martial_status">Martial Status</label>
<select name="martial_status" id="martial_status" class="form-control" value="<?php echo set_value('martial_status'); ?>">
<option value="">Select Martial Status</option>
<?php foreach ($martial_status as $status) { ?>
<option value="<?php echo $status['id'] ?>" <?php if ($status['id'] == set_value('martial_status')) echo "selected = 'selected'"?>><?php echo $status['status_name'] ?></option>
<?php } ?>
</select>
On generating the options tag check which option got selected and echo selected = 'selected' in the attribute of that option tag.
I have this problem that the selected value in my dropdownlist is showing twice. What should i do so that it will show only once.
<td>
<select class="span8" style="width:100%" name="from_time[]" id="from_time<?php echo $count;?>" value="start_from" onchange="calculate_by_ajax(this.id);">
<option value="<?php
$start_from=$jobs_result['start_from'];
//$date_arr_to= explode(" ", $start_from);
//$date_to= $date_arr_to[0];
//$time_to= $date_arr_to[1];
$sec="SELECT DATE_FORMAT('$start_from', '%H:%i') as tp";
$sec_exe=mysql_query($sec);
$sec_res=mysql_fetch_array($sec_exe);
?>" selected="selected">
<?php echo $sec_res['tp']; ?></option>
<?php include("list.php"); ?>
</select>
</td>
Got it, instead of modifying one of the available options and marking it as selected, you actually add another option with your code.
You could change list.php to look like this (i.e. an array of all the times)
<?php
$drop_down_values = array('11:35', '11:36', '11:27');
?>
Then your code should look like this:
<?php
include("list.php");
$start_from=$jobs_result['start_from'];
$sec="SELECT DATE_FORMAT('$start_from', '%H:%i') as tp";
$sec_exe=mysql_query($sec);
$sec_res=mysql_fetch_array($sec_exe);
?>
<td>
<select class="span8" style="width:100%" name="from_time[]" id="from_time<?php echo $count;?>" value="start_from" onchange="calculate_by_ajax(this.id);">
<?php foreach ($drop_down_values as $value) {
if ($value == $sec_rec) {
echo "<option selected=\"selected\">$value</option>";
} else {
echo "<option>$value</option>";
}
}
?>
</select>
</td>
Im trying to retrieve the value from a select box after the selected index has been changed. I keep getting an undefined index variable.
The form reloads the page so that I can update a table elsewhere on the page. The options are filled from the results of an SQL query.
The select box code.
<form action="" method="post">
<label>Select School</label>
<select class="form-control" name="schoolSelect" onchange="this.form.submit()">
<?php
foreach ($faculty as $key) { ?>
<option value="<?php echo $key['1']; ?>"><?php echo $key['1']; ?></option>
<?php } ?>
</select>
</form>
PHP used to retrive value
if (isset($_POST['schoolSelect'])){
$selectedSchool = $_POST['schoolSelect'];
$result = executeUserSelect($sqlUserBySchool, $db, $_POST['schoolSelect']);
}
EDIT
var dump =
array (size=1)
'schoolSelect' => string 'Plymouth Business School' (length=24)
Select box text = Plymouth Business School
Thanks in advance
Tony
<body>
<?php
if (isset($_POST['schoolSelect'])){
$selectedSchool = $_POST['schoolSelect'];
echo $selectedSchool;
}
else {
?>
<form action="" method="post">
<label>Select School</label>
<select class="form-control" name="schoolSelect" onchange="this.form.submit()">
<?php
foreach ($faculty as $key) { ?>
<option value="<?php echo $key['1']; ?>"><?php echo $key['1']; ?></option>
<?php } ?>
</select>
</form>
<?php } ?>
</body>
I am working on a dropdown change event, but I am not able to set a condition for the change event. For the second dropdown(subsel) I want a list of values for which the value in sel is NOT present. So far all I'm able to do is reflect the value in first select dropdown into the second dropdown.
<script>$(document).ready(function() {
$("#sel").live('change', function() {
$("#selsub").val($(this).val());
});
});</script>
<form method="get">
<label for="category">Parent Category</label>
<select name="sel" id="sel">
<?php
include('connection.php');
$query_parent=$query=mysql_query("SELECT * from stations");
<?php while($row = mysql_fetch_array($query_parent)): ?>
<option value="<?php echo $row['name']; ?>"><?php echo $row['name']; ?></option>
<?php endwhile;?>
</select>
<br/><br/>
<label>Sub Category</label>
<div class='detail'>
<select name="selsub" id="selsub">
<?php
$query=mysql_query("SELECT * from stations");
while($row1 = mysql_fetch_array($query)): ?>
<option value="<?php echo $row1['name']; ?>"><?php echo $row1['name']; ?></option>
<?php endwhile; ?>
</select>
</div>
Kindly help me to set a condition where in the second dropdown(selsub) all the values would appear except the value one in first dropdown(sel).
Try to do:
$(document).ready(function() {
$("#sel").on('change', function() {
selectedVal = this.value;
$("#selsub option[value='" + selectedVal +"']").hide();
});
});
I have some manufactures in my store and I want to modify the search so that you can choose the manufacture from a drop-down menu :)
I wish to change the search box into a drop-down menu in opencart. Is that possible? If yes, please tell me how.
Thank you !
Ok, I don't know why you are doing this, but here is one way...
I am using header search for this example, Opencart 1.5.4.1
Edit catalog/controller/commmon/header.php. After line 96:
$this->load->model('catalog/product');
add this:
// - - Manufacturers Dropdown Data Start - - - - - - - -
// load manufacturer model
$this->load->model('catalog/manufacturer');
//get manufacturers data
$manufacturers = $this->model_catalog_manufacturer->getManufacturers();
//populate data array for use in view
$this->data['manufacturers'] = array();
foreach ($manufacturers as $manufacturer){
$this->data['manufacturers'][] = array(
'id' => $manufacturer['manufacturer_id'],
'name' => $manufacturer['name']
);
}
// - - Manufacturers Dropdown Data End - - - - - - - - -
Now, in catalog/view/theme/xxx/template/common/header.tpl find search DIV, comment out the search input (lines 55-62):
<div id="search">
<!-- <div class="button-search"></div>
<?php if ($filter_name) { ?>
<input type="text" name="filter_name" value="<?php echo $filter_name; ?>" />
<?php } else { ?>
<input type="text" name="filter_name" value="<?php echo $text_search; ?>" onclick="this.value = '';" onkeydown="this.style.color = '#000000';" />
<?php } ?> -->
...
Add your select element:
<div id="search">
<!-- <div class="button-search"></div>
<?php if ($filter_name) { ?>
<input type="text" name="filter_name" value="<?php echo $filter_name; ?>" />
<?php } else { ?>
<input type="text" name="filter_name" value="<?php echo $text_search; ?>" onclick="this.value = '';" onkeydown="this.style.color = '#000000';" />
<?php } ?> -->
<select name='manuf_dropdown' ONCHANGE="location = this.options[this.selectedIndex].value;">
<option value=''></option>
<?php foreach ($manufacturers as $manufacturer) {
if (isset($_GET['manufacturer_id']) && $_GET['manufacturer_id'] == $manufacturer['id']){
?>
<option selected="selected" value="./?route=product/manufacturer/info&manufacturer_id=<?php echo $manufacturer['id'] ?>"><?php echo $manufacturer['name'] ?></option>
<?php } else { ?>
<option value="./?route=product/manufacturer/info&manufacturer_id=<?php echo $manufacturer['id'] ?>"><?php echo $manufacturer['name'] ?></option>
<?php }} ?>
</select>
</div>
Let me know if you need any explanation of the code.