/    Sign up×
Community /Pin to ProfileBookmark

blur problem in jQuery

hello guys.
I’m training on jQuery forms( focus, blur ) now. Here a screenshot of the form
[upl-image-preview url=https://www.webdeveloper.com/forum/assets/files/2019-01-08/1546972982-260496-untitled.jpeg]
The idea is, when a field loses focus, in image (green sign) appears to the right of it.
I used a for loop to apply the idea on all fields, but that never happens and no sign appears on blur.

here are the codes:
—————————-

=== HTML ===


*************

<head>
<link rel=”stylesheet” href=”css/style.css”>
<script src=”js/jquery-3.3.1.min.js”></script>
<script src=”js/plugins.js”></script>
</head>

<div class=”input_container”>
<label>UserName:</label>
<input type=”text” class=”focus”>
<img class=”pass” src=”images/true.png” width=”15″ height=”15″>
<span class=”fail”>username must me at least 10 characters</span><br>

<label>Password:</label>
<input type=”password” class=”focus”>
<img class=”pass” src=”images/true.png” width=”15″ height=”15″>
<span class=”fail”>password must me at least 8 characters</span><br>

<label>e-mail:</label>
<input type=”email” class=”focus” required>
<img class=”pass” src=”images/true.png” width=”15″ height=”15″>
<span class=”fail”>error email syntax</span><br>

<label>address:</label>
<input type=”text” class=”focus”>
<img class=”pass” src=”images/true.png” width=”15″ height=”15″>
<span class=”fail”></span><br>

<label>phone:</label>
<input type=”tel” class=”focus”>
<img class=”pass” src=”images/true.png” width=”15″ height=”15″>
<span class=”fail”>Numbers only are allowed</span><br>

</div>

=== CSS ===


*************

.pass
{
display: none;
}

.fail
{
display: none;
}

.input_container
{
border: 1px solid #000;
border-radius: 10px;
padding: 10px;
width: fit-content;
box-shadow: 2px 2px 10px;
border-bottom:

}
.input_container input
{
border-color: #f00;
border-radius: 5px;
margin-left: 10px;
}

=== jQuery===


*************

/// focus effect
//**************

$(‘.focus’).on(‘focus’,function(){
$(this).css(‘backgroundColor’,’#ccc’)

})

// blur effect
//**************

for (var i = 1; i <= $(‘.focus’).length; i++)
{
$(‘.input_container .focus:nth-of-type(‘+i+’)’).on(‘blur’,function()
{
$(this).css(‘backgroundColor’,’transparent’)

$(‘.pass:nth-of-type(‘+i+’)’).fadeIn(1000)
}
)}

to post a comment

5 Comments(s)

Copy linkTweet thisAlerts:
@HanyTauthorJan 11.2019 — @rick1221#1599805 Thanks, but I still don't understand why the green sign doesn't appear on input text blur.
Copy linkTweet thisAlerts:
@SempervivumJan 12.2019 — No need to use Javascript or jQuery, this can be done easily by a few lines of CSS:

http://jsfiddle.net/Sempervivum/hs26wb85/13/
Copy linkTweet thisAlerts:
@rootJan 12.2019 — The big question is, where is the form?

I suggest you lean how to make a proper HTML5 web form before you start with scripting languages that are add on tools like JQuery.

You really need to learn html5 first and CSS next, then JavaScript after that, another browser languages, then things like JQuery. For me those are not helpful, they just bloat a site needlessly. I then get the same old lame retort that it can be minified, it is still BLOAT!!!
Copy linkTweet thisAlerts:
@HanyTauthorJan 19.2019 — @Sempervivum#1599886 Thanks bro. You are right, no need for jQuery
Copy linkTweet thisAlerts:
@ashokapackersJan 21.2019 — Ashoka Packers and Movers in Whitefield, Hyderabad, one of the trusted and moderate transporter, give great help family merchandise, modern products, vehicles transportation at the best cost from one area to other sheltered and secure. Everything is finished by master experts and deal with the best managerial group. They deal with all the work and make each migration solid and advantageous for their help.

Contact Us: 9000809809

Get more details to visit us: http://bit.ly/2Rfy3ri
×

Success!

Help @HanyT spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...