Click here to Skip to main content
14,391,319 members
Rate this:
Please Sign up or sign in to vote.
Hi,

I have a page which is having two textboxes and one more link (a href ) and Next button to go for next page.

All are mandotory fields.


Now In case user forgot/missed to click on the Link ,and click on next/submit button ,I need to give a pop up by stating "Please click on the link " and redirect the flow to linked page once he clicked on pop up.This pop up will display only in this condition only


I have tried not select tag in Jquery but unable to get the logic for whether the link is clicked or not?

Please suggest me how to do with Jquery,JS, jsp.


Thanks .
Posted
Updated 28-Aug-14 5:26am
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

I would recommend using the custom data- attribute on the element. Make your link look something like...

<a href="some link" id="infoLink" data-clicked="false" ...="">
</a>


then using the attr() function in jQuery you can read and set the value.

Example:
$("#nextButton").click(function(event) {
    if(false == $("#infoLink").attr("data-clicked")) {
        // display your popup
        
        // prevent event from going any further
        event.stopPropagation();
    }
});

$("#infoLink").click(function() {
    // change the custom data attribute
    $(this).attr("data-clicked", "true");
});
   
Comments
Sergey Alexandrovich Kryukov 28-Aug-14 16:21pm
   
This technique should work, only the use of "data-..." attribute is totally redundant (and may not be supported by all browser; I'm not sure).
This is Javascript; you can add any property to the object (in this case, wrapper returned from selector #('...')). On first call, this property will be underfined, but on $("#infoLink") click you add the property, so it becomes some defined object on next $("#nextButton") click, which can be checked up with simple "if(wrapperObject)". It will make this code much simpler and less depending on the browser.
—SA
Dennis E White 28-Aug-14 16:27pm
   
I have used the "data-" attribute with IE 8+, chrome, firefox and safari and haven't had any issues with it. with later releases of HTML the requirement/support was formalized and actually included into the spec.
Sergey Alexandrovich Kryukov 28-Aug-14 16:56pm
   
All right, good to know, thank you. Still, its use is redundant, because no attribute is really needed when jQuery wrapper objects are used.
—SA
pratap420 30-Aug-14 1:57am
   
Thanks all for your suggestions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100