Hello, welcome to therichpost.com. In this post, I will tell you Jquery all time methods and functions. I personally like jquery very much. Most of my code is full with jquery. When I stuck in php or other language then that stuckness I remove with jquery code.
Today In this post, you will more code related to jquery.
1. jquery differents click functions:
$(“Div#id”).click(function(){
//you code
});
// for dynamic htmls
$(“Div#id”).on(‘click’, function(){
//you code
});
$(“Div#id”).on(‘click’, ‘.divclass’, function(){
//you code
});
2. Open Bootstrap Modal Popup with jquery:
$(‘#ModalId’).modal(‘show’);
3. Add css to div with jquery:
$(‘#DivId’).css(‘width’, ‘100px’);
4. Remove commas in array data with jquery:
arr.join(“\n”)
There are so many jquery code, tricks and i will let you know all. Please do comment if you any query related to this post. Thank you. Therichpost.com
// jquery custom validations on button click
$(“.formbtn”).on(“click”, function(){
var i=0;
var j=0;
if($(“#firstname”).val()==””)
{
i = 1;
$(“#firstname”).css(“border”, “1px solid red”);
}
else
{
i = 0;
$(“#firstname”).css(“border”, “1px solid rgba(0, 0, 0, 0.15)”);
}
if($(“#lastname”).val()==””)
{
j=0;
$(“#lastname”).css(“border”, “1px solid red”);
}
else
{
j = 0;
$(“#lastname”).css(“border”, “1px solid rgba(0, 0, 0, 0.15)”);
}
if(i==0 && j==0)
{
alert(“All Done :)”);
}
else
{
alert(“All Not Done :(“);
}
});
// get select box text value on change event
$(“.addnewservice .select-service”).on(“change”, function(){
var optionSelected = $(this).find(“option:selected”);
var valueSelected = optionSelected.val();
var textSelected = optionSelected.text();
});
thank you alexa
Here more:
========
set default flag in intl-tel-input
open -> intlTelInput.min.js -> find-> preferredCountries-> add county code:
That is it
Please help:
How to write a JavaScript code using if condition….user status should active its show green color button on…..it user status is disable it shows red color button
Here you can check the answer:
if($(“#divwhereuserstatus”).text()==”active “)
{
$(“#button”).css(“background-color”, “green”);
}
else
{
$(“#button”).css(“background-color”, “red”);
}
Hope this solve your problem..
sir how to do this through using ajax call using if condtion in javascrit
for ajax use this:
$.ajax({
type: ‘POST’,
url: “url.php?action=saveData”,
data: data,
success: function(resultData) { if($(“#divwhereuserstatus”).text()==”active “)
{
$(“#button”).css(“background-color”, “green”);
}
else
{
$(“#button”).css(“background-color”, “red”);
} }
});
okay sir
success: function( result){
console.log(result);
if(userstatus == 1){
$(“#active”).show();
}
else{
$(“#inactive”).show();
like this but i m not getting
success: function( result){
console.log(result);
if(userstatus == 1){
$(“#active”).show();
}
else{
$(“#inactive”).show();
like this but i m not getting
fine…
but i m not getting output sir
give me your file or complete code for this..
var error = “”;
$(document).ready(function(){
$(“#submit”).on(“click”, function(){
$(“.error”).html(“”);
var number = $(“#zip”).val(),
userstatus = 1;
flag = true;
if(number === “” || !regex(number)){
error= “Enter correct 6 digit number Eg:123456”;
flag = false;
}
if(!flag){
$(“.error”).html(error).css({“color”:”#FF0000″ , “font-weight”:”bold” , “text-align”: “center” , “margin”: “px 0px”});
}
else{
$.ajax({
data : {“layout” : 1000, “fname” :name ,”lname”:lname, “email”: email, “password” : password , “gender” : gender},
method : “POST”,
success: function( result){
console.log(result);
if(userstatus == 1){
$(“#active”).show();
}
else{
$(“#inactive”).show();
}
},
})
}
})
})
html
Enter Your Details
Active
Inactive
Enter Your Details
Active
Inactive
var error = “”;
$(document).ready(function(){
$(“#submit”).on(“click”, function(){
$(“.error”).html(“”);
var number = $(“#zip”).val(),
userstatus = 1;
flag = true;
if(number === “” || !regex(number)){
error= “Enter correct 6 digit number Eg:123456”;
flag = false;
}
if(!flag){
$(“.error”).html(error).css({“color”:”#FF0000″ , “font-weight”:”bold” , “text-align”: “center” , “margin”: “px 0px”});
}
else{
$.ajax({
data : {“layout” : 1000, “fname” :name ,”lname”:lname, “email”: email, “password” : password , “gender” : gender},
method : “POST”,
success: function( result){
console.log(result);
if(userstatus == 1){
$(“#active”).show();
}
else{
$(“#inactive”).show();
}
},
})
}
})
})
HTML
Enter Your Details
Active
Inactive
Okay let me know you….
how to pass this value n id at the time of onsubmit in javascript
here is an example:
document.getElementById(“myForm”).onsubmit = function() {
alert(document.getElementById(“textboxid”).value);
}
sir i want to learn javascript n jquery can u suggest links n tutorilals
I can teach you..
sir if i need any help regarding coding validation wud u guide me
please check here
https://therichpost.com/learn-jquery
sir y is localstorage.getitem is used
The localstorage.getitem() method of the Storage system, when passed a key name, will return that key’s value.:
======================
var currentColor = localStorage.getItem(‘bgcolor’);
document.getElementById(‘bgcolor’).value = currentColor;
//also you can store temprary value like below method
// Save data to the current local store
localStorage.setItem(“username”, “John”);
// Access some stored data
alert( “username = ” + localStorage.getItem(“username”));
its like when we login as a user his details shud b appeared on top right corner ..like example in gmail we login n compose mail everythin n wen to signout wil go to our profile pic n signout ryt…..it should show our profile until we are in that page ..otherwise logout
They are called sessions. Store user information through login.
//also you can store temprary value like below method
// Save data to the current local store
localStorage.setItem(“username”, “John”);
// Access some stored data
alert( “username = ” + localStorage.getItem(“username”));
how to access using json
yea sessions….n hav to access data thru json
First tell me which framework you are working?
yea these session hav to access it through json
First tell me which framework you are working?
bootstrap
we cannot get json data in bootstrap or you can create it static data?
how
with this we create custom json data in js:
var data = {‘name’: ‘therichpost’, ‘age’: 1};
with this we create custom json data in js:
<script type=”text/javascript”>
var data = {‘name’: ‘therichpost’, ‘age’: 1};
</script>
this thing hav to put in js folder..
actually i tried with
if(session === “”){
localStorage.getItem(“session”);
{“session” :
{ “name”: “abc”}
}
window.location=”login.php”;
}
try this:
var session = { ‘session’: ‘abc’};
localStorage.setItem(‘session’, JSON.stringify(session));
session = JSON.parse(localStorage.getItem(‘session’));
if(session[‘session’]!=””)
{
window.location=”login.php”;
}
try this:
var session = { ‘session’: ‘abc’};
localStorage.setItem(‘session’, JSON.stringify(session));
session = JSON.parse(localStorage.getItem(‘session’));
if(session[‘session’]!=””)
{
window.location=”login.php”;
}
i tried
Okay then what?
its not taking
but I checked above code and it is working.
Did you paste that code in script tags?
we can get localStorage data in whole website:
if (localStorage) {
var data = JSON.parse(localStorage.getItem(‘session’));
alert(data[‘session’])
}