Showing posts with label Select. Show all posts
Showing posts with label Select. Show all posts

Feb 13, 2016

[Fixed Solution] Check For The Existence Of Option In Select Using JQuery

In this article I'm going to show you all, how to check for <option>'s existence in a <select> tag. Their are many ways to do this. Lets see a simple way of it.

First lets have a look on my drop down. 

1
2
3
4
5
6
7
8
9
<html>
<body>
    <select id="ddMember">
        <option value="Nifal">Nifal</option>
        <option value="Asjad">Asjad</option>
        <option value="Dinesh">Dinesh</option>
    </select>
</body>
</html>

Now lets say you wanted to check for the existence of the member "Gowtham" in the above drop-down. Use below java script codes to check it. 

1
var isExist = $('#ddMember option:contains("Gowtham")').length;

Above code will check for the given option. If value is not exist it will return zero(0). Otherwise it will return some other number, depending on the occurrences. 
Lets say, you wanted check for a option and if not available you wanted add it to your drop-down, simply use your below codes to do it. 

1
2
3
if($('#ddMember option:contains("Gowtham")').length){
  $('#ddMember').append("<option value="Gowtham">Gowtham</option>");
}

Hope you found, what you looked for.


Nov 5, 2014

Currency Conversion Using Yahoo API in Java Script

When You Want To Convert Currency From One Currency To Another, You Need To Use A Currency Conversion. Their Are Many APIs Which Allows To Convert Currency. In This Example I Will Demonstrate You To Use Yahoo API To Convert Currency.

Below Html Pages Uses The Yahoo API To Get The Currency Rate,

<html>
  <head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.4/jquery.mobile-1.4.4.min.css">
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
function getRate(){
var sFrom = $("#sFromCurrency" ).val();
var sTo = $("#sToCurrency" ).val();
var url = "http://query.yahooapis.com/v1/public/yql?q=select%20rate%2Cname%20from%20csv%20where%20url%3D%27http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes%3Fs%3D"+sFrom+sTo+"%253DX%26f%3Dl1n%27%20and%20columns%3D%27rate%2Cname%27&format=json";
$.ajax({
url: url,
type: "POST",
async: false,
processData: true,
data: "",
contentType: "application/json",
dataType: "jsonp"
}).done(function (data) {
$("#rate").html(data.query.results.row.rate);
});
}
</script>
</head>
<body>
<div data-role="page" id="pageone">
<div id="CurrencyFrom">
<span>Currency From </span>
<select id="sFromCurrency">
<option value="USD">USD</option>
<option value="GBP">GBP</option>
<option value="EUR">EUR</option>
<option value="LKR">LKR</option>
<option value="AUD">AUD</option>
</select>
</div>
<div id="CurrencyTo">
<span>Currency To </span>
<select id="sToCurrency">
<option value="USD">USD</option>
<option value="GBP">GBP</option>
<option value="EUR">EUR</option>
<option value="LKR">LKR</option>
<option value="AUD">AUD</option>
</select>
</div>
<div>
<input type="button" value="Check Rate" onclick="getRate()">
</div>
<div>
<span>Rate : </span>
<span id="rate">1.00</span>
</div>
</div>
  </body>
</html>


JWT Token Decode Using Jquery

When it come to authentication we use many mechanism. Ones the user authenticated we must keep these details somewhere safe. So we can share...