/    Sign up×
Community /Pin to ProfileBookmark

js logon validation

I am trying to implement a simple client side validation to ensure the user has logged on. Yes, I know I can’t rely upon client side validation, and will also implement albeit less elegant server side validation for non-javascript enabled users.

If the user hasn’t logged in (as determined by 1<>2 in my example), then I want an alert window to pop up and the link not to be followed. Can anyone comment how I should modify this script to do so. Thanks

[code=html]<head><script type=”text/javascript”>
function check_if_logged_on() {
if(1==2) //check if js session set
{return true;}
else
{alert(“Please Log In”); return false;}
}
</script></head>
<body>
<A HREF=”nextpage.php” onClick=”check_if_logged_on()”;>Link</a>
</body>
</html>[/code]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@NotionCommotionauthorFeb 11.2007 — I have somewhat of a fix by adding the return in my onClick statement. It does leave window.status with the non-followed link name on FF, but not in IE. For learning purposes, I would appreciate any comments on how I am trying to implement and the use of return false to stop process. Thanks

[code=html]<script type="text/javascript">
function check_if_logged_on() {
if(1==2) //check if js session set
{return true;}
else
{alert("Please Log In");
// window.status = '';
return false;}
}
</script>
</head>
<body>
<A HREF="somewhere.html" onClick="return check_if_logged_on()";>Link</a>
</body>
</html>[/code]
×

Success!

Help @NotionCommotion 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 5.6,
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,
)...