search form - 2 values in 1 option - wordpress

So I have this code into a search form:
<select name="rentbuy">
<option value="buy">Buy</option>
<option value="rent">Rent</option>
<option value="rent/week">Rent/week</option>
</select>
This is what I want to do:
<select name="rentbuy">
<option value="buy">Buy</option>
<option value="rent rent/week">Rent</option>
</select>
So when someone chooses "Rent" I want the form to get both values "rent" and "rent/week".
Thanks.

Use multiple attribute on select element :
<select name="rentbuy" multiple="multiple">
<option value="buy">Buy</option>
<option value="rent" selected="selected">Rent</option>
<option value="rent/week" selected="selected">Rent/week</option>
</select>
Here is a jsfiddle : http://jsfiddle.net/v2wHS/

I have this code into the theme, maybe helps with something:
$search_buyorrent = "";
if (get_option('wp_search_bor') == "Yes") {
if (isset($_COOKIE['rentbuy']) && $_COOKIE['rentbuy'] != '') {
$search_buyorrent = $_COOKIE['rentbuy'];
} else {
if (isset($_POST['rentbuy'])) {
$search_buyorrent = trim($_POST['rentbuy']);
}
}
} else {
$search_buyorrent = '';
}
And another snippet here:
if ($search_buyorrent == "buy" || $search_buyorrent == "") {
$query ="SELECT p.* FROM $wpdb->posts p, $wpdb->postmeta p1
WHERE p.ID = p1.post_id AND p1.meta_key='price_value' AND convert(p1.meta_value, signed) BETWEEN '$search_pricemin_buy' AND '$search_pricemax_buy'";
$spm = getIds( $query );
$_ids = ( !empty($spm) ? ( !empty($_ids) ? array_intersect( $_ids, $spm) : "" ) : "" );
}

Related

Filter Select Symfony Dom Crawler

I have html like this :
<select name="MySelect" id="MySelectID">
<option value="0">One</option>
<option value="1">Two</option>
<option value="2">Three</option>
</select>
And i want to get all the option inner text One, Two, and Three
How to do this using Symfony Dom Crawler ?
You can easy use the tag names for the path like $crawler->filter('select > option').
$crawler = new \Symfony\Component\DomCrawler\Crawler('
<select name="MySelect" id="MySelectID">
<option value="0">One</option>
<option value="1">Two</option>
<option value="2">Three</option>
</select>
');
$result = [];
foreach ($crawler->filter('select > option') as $domElement) {
$result[] = $domElement->textContent;
}
// $result is ['One', 'Two', 'Three']

ASPX Select dropdown with Button Linking to another page

I am unfamiliar with select dropdowns and links. If I have:
<select>
<option value="">Select</option>
<option value="/Applications.aspx">Applications</option>
<option value="/EditApplications.aspx">Edit Application</option>
<option value="/AddApplications.aspx">Add Applications</option>
</select>
<button>Go</button>
When the user selects their option, how do I link the button to when the user clicks the button, it goes to the selected page within the dropdown in ASPX? I am sure I need to bind it somehow to the codebehind but I am not sure how to do this.
A very basic solution would be something like the snippet below. On the button click read the value of the select and redirect to that url. Don't forget to add an id to the select. And you need to add type="button" to the button, otherwise it will trigger a form post.
<select id="MySelect">
<option value="">Select</option>
<option value="/Applications.aspx">Applications</option>
<option value="/EditApplications.aspx">Edit Application</option>
<option value="/AddApplications.aspx">Add Applications</option>
</select>
<button type="button" onclick="GoTOUrl()">Go</button>
<script>
function GoTOUrl() {
var url = $('#MySelect').val();
if (url === '')
return;
location.href = url;
}
</script>
No need to wire it up to the code behind. This can all be handled client side with some javascript.
Make the button an actual link. Then update the href attribute and optionally the text.
//Get relevent elements
var linkDropDown = document.getElementById("MySelect");
var link = document.getElementById("Link");
//Wire up event listener to the dropdown
linkDropDown.addEventListener("change", function() {
var defaultVal = this.options[0].value;
//Toggle the inactive class based on selected value
link.classList.toggle("inactive", this.value === defaultVal);
//Set Href
link.href = this.value;
//Set Text using ternary operation
link.text = this.value === defaultVal ? "Go.." : "Go to " + this.options[this.selectedIndex].text;
});
.inactive {
pointer-events: none;
color: grey;
}
<select id="MySelect">
<option value="/">Select</option>
<option value="/Applications.aspx">Applications</option>
<option value="/EditApplications.aspx">Edit Application</option>
<option value="/AddApplications.aspx">Add Applications</option>
</select>
Go..
It is also possible to encapsulate this to automagically work if you have more than set of this on the page.
//Get relevent elements
var dropdowns = document.querySelectorAll(".dropdownSelect");
//Wire up event listeners
for(var i = 0; i < dropdowns.length; i++){
dropdowns[i].addEventListener("change", function(event){
if(event.target.nodeName === "SELECT") {
let sel = event.target;
let link = this.querySelector(".dropdownLink");
let defaultVal = sel.options[0].value;
//Toggle the inactive class based on selected value
link.classList.toggle("inactive", sel.value === defaultVal);
//Set HREF
link.href = sel.value;
//Set Text using ternary operation
link.text = sel.value === defaultVal ? "Go.." : "Go to " + sel.options[sel.selectedIndex].text;
}
})
}
.inactive {
pointer-events: none;
color: grey;
}
<div class="dropdownSelect">
<select>
<option value="/">Select</option>
<option value="/Applications.aspx">Applications</option>
<option value="/EditApplications.aspx">Edit Application</option>
<option value="/AddApplications.aspx">Add Applications</option>
</select>
Go..
</div>
<div class="dropdownSelect">
<select>
<option value="/">Select</option>
<option value="/WebSites.aspx">Web Sites</option>
<option value="/EditWebSites.aspx">Edit Web Sites</option>
<option value="/AddWebSites.aspx">Add Websites</option>
</select>
Go..
</div>

check wordpress select box value

How to check if a select box has a value or not in wordpress by php?
I want to check if a select box has a value and if it has then check the value against $post array generated by for-each loop.
Is there any built in wordpress function?
Thanks.
We can use php function in wordpress actions for example:
<select name="select_value">
<option value="">Default value (key thing is leaving value="")</option>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
//check in the action or filter for the drop-down value:
if($_POST['select_value'] != '') {
//do something
echo $_POST['select_value'];
} else {
//if not post any value
}
This function may be helpful for you:
selected( $selected, $current, $echo);
$selected (required) = One of the values to compare.
Default: None
$current (optional) = The other value to compare if not just true.
Default: true
$echo(boolean) (optional) = Whether to echo or just return the string.
Default: true
Ref.link: https://codex.wordpress.org/Function_Reference/selected may be helpful for you.

how to get the selected value from a drop down list and transfer it to a viewbag

View
...Some Codes...
<select class="form-control" style = "width:400px">
<option selected> select issue type </option>
#foreach( var item in Model._issueList)
{
<option>#item.issueName</option>
}
</select>
...Some Codes...
Output of my dropdown
dropDown: issue_one, issue_two, issue_three
Now I want to choose my issue_three in my drop down and save it in a Viewbag.select, want should be the proper code so that I can transfer the issue_three to my Viewbag.select
TEST
...foreach code...
Viewbag.select = ????
View
<select class="form-control" style = "width:400px">
<option selected> Select Company Name </option>
#foreach (var item in Model._issueList)
{
<option id="issueSelect" onclick="transferIssue('#item.issueNo')">#item.issueName</option>
}
</select>
#Html.HiddenFor( m => m.variable,new { #class = "form-control", style = "width:400px", #id = "issue" })
...Some codes...
<button type ="submit" id='submit_button'>Submit</button>
SCRIPT Use JQUERY
function transferIssue(x){ $('#issue')val(); }
jQuery(document).on('click', '#submit_button', function (ev) {
ev.preventDefault();
var _issue = jQuery('#issue').val();
var _url = '#Url.Action("Jobs")' + '?value='+ _issue;
window.location.href = _url;
});

Codeigniter populating drop down from database

Hello friends i am having a problem with codeigniter drop down list....
it is working finely but there is a problem which i m unable to solve...
coming direct to code here is my *mode*l ..
function getBatchId(){
$batchId = $this->db->get('batch');
$batchList = array();
if($batchId->num_rows() >0){
foreach ($batchId->result_array() as $tablerow) {
$batchList[] = $tablerow['code'];
}
return $batchList;
}else {return false;}
my controller
$this->load->model('AdmissonModel');
$content = array(
'progid' => $this->AdmissonModel->getProgrameCode(),
'batch' => $this->AdmissonModel->getBatchId(),
'depid' => $this->AdmissonModel->getDepId()
);
$this->load->view('Admissions/admForm_view',$content);
and my view
<tr>
<td>BATCH</td>
<td><?php echo form_dropdown('Batch',$batch); ?></td>
</tr>
the result produced is like this
<select name="Batch">
<option value="0">BCS12</option>
<option value="1">BCS14</option>
<option value="2">IMS01</option>
<option value="3">INU01</option>
<option value="4">INU02</option>
<option value="5">INU03</option>
</select>
now the problem is that i want the values also like BCS12,BCS14,IMS01 etc not 0,1,2,3...but the values are 0,1,2,3,4.....can any 1 help me plz...thanks alot in advance
in your model update this function to
function getBatchId(){
$batchId = $this->db->get('batch');
$batchList = array();
if($batchId->num_rows() >0){
foreach ($batchId->result_array() as $tablerow) {
$batchList[$tablerow['code']] = $tablerow['code'];
}
return $batchList;
}else {return false;}

Resources