I am newbie in javascript and html5. I am trying to achieve the following:
I have a drop down with the below values:
Everything:
From:
To:
User will have a text box to enter the search term. When the user enters a text like "blah" and selects "From:" in the drop down and hits enter, the text in the text box should say "From: blah" and searches all the messages from Blah.
This is a feature in Outlook that i am trying to implement. I have tried to use chosen js but could not proceed much. Could anyone provide any pointers?
Assume this is your html:
<select id="cmbClause">
<option value="1">Everything:</option>
<option value="2">From:</option>
<option value="3">To:</option>
</select>
<input type="text" id="txtSearch" />
<input type="text" id="txtResult" />
Then try jQuery script below:
$(function(){
$('#txtSearch').keypress(function(e) {
// if user press "Enter" on txtSearch and txtSearch not empty
if(e.keyCode==13 && $('#txtSearch').val().trim()!="") {
$('#txtResult').val(setClause($('#cmbClause').val()) + $('#txtSearch').val());
}
});
function setClause(val) {// Get select (dropdown) value and return string
var clause;
switch(val) {
case '1': clause = "Everything "; break;
case '2': clause = "From "; break;
case '3': clause = "To "; break;
}
return clause;
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.