Jinbom Heo
Jinbom Heo

Reputation: 7400

conditional anchor tag control

in html,

<a href="/shop/view-item.php" onclick="checklogin();">View Item</a>

As you know, the execution order is,

1) onclick javascript function, checklogin,
2) go to href link, and page refresh, /shop/view-item.php

And if you add 'return false' in onclick function's foot, href doesn't work. so the page remain on the same page. The code is,

<a href="/shop/view-item.php" onclick="checklogin();return false;">View Item</a>

My question, Can I control 'return false' effect? If user do not log, I want to user remain the same page with alert logging request. If user logged already, let him go the anchor's link url.

Is it possible?

Upvotes: 4

Views: 2524

Answers (1)

marramgrass
marramgrass

Reputation: 1411

Make sure your checklogin() function will return true or false appropriately, then do the following:

<a href="/shop/view-item.php" onclick="return checklogin();">View Item</a>

Upvotes: 7

Related Questions