dropdown with php link - php

I have a dropdown list with customer names from database. I want these values to be a link with my 'href' attribute. How can I do it?
<select class="feedback-input" id="customer_selecter" name="customerName">
<option >Select customer</option>
<?php foreach ($customers as $row): ?>
<a href="<?php echo base_url() . "index.php/edit/show_customer_id/" . $row->customerID; ?>">
<?php echo '<option value="'.$row->customerID.'">'.$row->customerName.'</option>'; ?></a>
<?php endforeach; ?>
</select>

try this:
<select class="feedback-input" id="customer_selecter" name="customerName">
<option >Select customer</option>
<?php foreach ($customers as $row): ?>
<a href="<?php echo base_url() . 'index.php/edit/show_customer_id/' . $row->customerID; ?>">
<option value="<?php echo $row->customerID; ?>"><?php echo $row->customerName; ?></option>
</a>
<?php endforeach; ?>
</select>
but this is not a valid html, because you're using a <a> tag inside a <select> tag, try doing this with javascript instead like this :
<select class="feedback-input" id="customer_selecter" name="customerName" onchange="location = this.value;">
<option >Select customer</option>
<?php foreach ($customers as $row): ?>
<option value="<?php echo base_url() . 'index.php/edit/show_customer_id/' . $row->customerID; ?>"><?php echo $row->customerName; ?></option>
<?php endforeach; ?>
</select>

Related

problem in getting values from select options

below is the code which i have problem and the problem is how can i get values if value="php echo $someting;" instead of value="someting"
like how i put value when i use condition if($_POST['city']=='')
how can i put echo value in if statement
anyone got my point then please answer.
<select class="js-example-placeholder-single js-states form-control" id="city" name="city"
title="Select City" data-hide-disabled="true" data-live-search="true">
<optgroup label="Location">
<option value="">No Selection</option>
<?php
$cities = $db->get ("cities");
foreach ($cities as $city){
?>
<option value="<?php echo $city['city_name']; ?>" <?php if($city['city_name'] ==
$selected_city) echo "selected"; ?> >
<?php echo $city['city_name']; ?>
</option>
<?php } ?>
</optgroup>
</select>
Just add empty($_POST['city']) ? 'selected' : '' on empty option:
<?php
$selected_city = $_POST['city'] ?? null;
?>
<select class="js-example-placeholder-single js-states form-control" id="city" name="city" title="Select City" data-hide-disabled="true" data-live-search="true">
<optgroup label="Location">
<option value="" <?= empty($selected_city) ? 'selected' : ''; ?>>No Selection</option>
<?php
$cities = $db->get("cities");
foreach ($cities as $city):
?>
<option value="<?= $city['city_name']; ?>" <?= $city['city_name'] == $selected_city ? 'selected' : ''; ?>>
<?= $city['city_name']; ?>
</option>
<?php endforeach; ?>
</optgroup>
</select>

Why I can't use chained jquery in loop condition?

<?php
foreach ($employee as $data) {
?>
<tr>
<td>
<form action="<?php echo base_url();?>controller_admin/updateEmployee/<?php echo $data->id_employee;?>" method="post">
<select style="width: 100px; height: 33px;" name="directorate" id="directorate">
<option selected value="<?php echo $data->id_directorate ?>"><?php echo $data->directorate ?></option>
<?php
foreach ($directorate as $key) {
if ($data->directorate != $key->directorate) {?>
<option value="<?php echo $key->id_directorate ?>">
<?php echo $key->directorate; ?>
</option>
<?php
}
}
?>
</select>
</td>
<td>
<select style="width: 100px; height: 33px;" name="department" id="department">
<?php if ($data->id_department!=null) {?>
<option value="0"></option>
<?php
} ?>
<option selected value="<?php echo $data->id_department ?>"><?php echo $data->department; ?></option>
<?php
$value = 1;
foreach ($department as $key) {
if ($data->department != $key->department) {?>
<option
class="<?php echo $key->id_directorate ?>"
value="<?php echo $value ?>">
<?php echo $key->department; ?>
</option>
<?php
$value++;
}
}
?>
</select>
</td>
<td>
<select style="width: 100px; height: 33px;" name="section" id="section">
<?php if ($data->id_section!=null): ?>
<option value="0"></option>
<?php endif ?>
<option selected value="<?php echo $data->id_section ?>"><?php echo $data->section; ?></option>
<?php
$value = 1;
foreach ($section as $key) {
if ($data->section != $key->section) {?>
<option
class="<?php echo $key->id_department ?>"
value="<?php echo $value ?>">
<?php echo $key->section; ?>
</option>
<?php
$value++;
}
}
?>
</select>
</td>
<td>
<button type="submit" class="btn btn-warning"><i class="fa fa-edit"></i></button>
<button type="button" class="btn btn-danger"><i class="fa fa-trash-o"></i></button>
</form>
</td>
<?php
}
?>
<script src="<?php echo base_url();?>assets/js/jquery.chained.min.js"></script>
<script>
$("#department").chained("#directorate");
$("#section").chained("#department");
</script>
I want to make a list of table to display chained dropdown to display like this:
and chained dropdown work like this:
but, it will display in first row only, at another row, it does not work.
You can look like this:
I hope I can chained dropdown for all rows. Anyone find the solution?
you could try to put your js code inside the ready function - its possible that the elements are not even rendered when you try to select them.
<script>
$( document ).ready(function() {
$("#department").chained("#directorate");
$("#section").chained("#department");
});
</script>
reference: http://learn.jquery.com/using-jquery-core/document-ready/

Update Dropdown Value

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 customize values on products filter bar wordpress

I need to modify the value and name of the products filter in a Wordpress template that I've purchased.
The template is Automotive - Templatic. I need to change values and name of filter products filter. I'm trying to change this PHP code:
<form id="search_car" name="search_car" action="<?php echo home_url(); ?>" method="get">
<input type="hidden" name="search" id="search" value="vehicle" />
<div class="selectbox select1">
<input type="text" value="<?php the_search_query(); ?>" name="s" id="s" placeholder="<?php _e('Model , Name etc...',T_DOMAIN); ?>">
</div>
<span class="shape2"><?php _e('OR',T_DOMAIN); ?></span>
<?php if($post_category): ?>
<div class="selectbox select2">
<select class="select" title="<?php _e("All Makes",T_DOMAIN); ?>" name="makes" id="makes">
<option value=""><?php _e("All Makes",T_DOMAIN); ?></option>
<?php
$args = array( 'taxonomy' => 'vcategory' );
$terms = get_terms( 'vcategory',$args);
foreach ( $terms as $term ):
?>
<option value="<?php echo $term->term_id; ?>" <?php if($_REQUEST['makes'] == $term->term_id){ ?> selected="selected" <?php } ?>><?php echo esc_attr( $term->name ); ?></option>
<?php endforeach; ?>
</select>
</div>
<?php endif; ?>
<?php if($model_status): ?>
<div class="selectbox select2">
<select class="select" title="<?php _e('All Models',T_DOMAIN); ?>" name="status" id="model_status">
<option value=""><?php _e('All Models',T_DOMAIN); ?></option>
<?php
$explode = explode(",",$option);
foreach($explode as $_explode):
?>
<option value="<?php echo $_explode; ?>" <?php if($_REQUEST['status'] == $_explode){ ?> selected="selected" <?php } ?>><?php echo sprintf(__('%s',T_DOMAIN),$_explode); ?></option>
<?php endforeach; ?>
</select>
</div>
<?php endif; ?>
<?php if($fuel): ?>
<div class="selectbox select2">
<select class="select" title="<?php _e('All Type',T_DOMAIN); ?>" name="fuel" id="fuel">
<option value=""><?php _e('All Type',T_DOMAIN); ?></option>
<?php
$fuel_exp = explode(",",$fuel_option);
foreach($fuel_exp as $_fuel_option):
?>
<option value="<?php echo $_fuel_option; ?>" <?php if($_REQUEST['fuel'] == $_fuel_option){ ?> selected="selected" <?php } ?>><?php echo sprintf(__('%s',T_DOMAIN),$_fuel_option); ?></option>
<?php endforeach; ?>
</select>
</div>
<?php endif; ?>
I have to create 3 dropdown fields and 1 text area field. Can you help me?
Thanks in advance...

Magento: Get country that user has chosen

I have a piece of code which creates dropdown list of the countries
<div class="input-box">
<?php $_countries = Mage::getResourceModel('directory/country_collection')->loadData()->toOptionArray(false) ?>
<?php if (count($_countries) > 0): ?>
<select name="country" id="country" onchange="print()">
<option value=""> </option>
<?php foreach($_countries as $_country): ?>
<option value="<?php echo $_country['value'] ?>">
<?php echo $_country['label'] ?>
</option>
<?php endforeach; ?>
</select>
<?php endif; ?>
</div>
I can't figure out how to get the country which user has chosen. Can you please help me?
<div class="input-box">
<?php $_countries = Mage::getResourceModel('directory/country_collection')->loadData()->toOptionArray(false) ?>
<?php if (count($_countries) > 0): ?>
<select name="country" id="country" onchange="showCountry(this)">
<option value=""> </option>
<option value="<?php echo $_country['value'] ?>" <?php echo $select; ?> >
<?php echo $_country['label'] ?>
</option>
<?php endforeach; ?> </select>
<?php endif; ?>
</div>
function showCountry​(ele){
alert(ele.value);
} ​

Categories