Search code examples
javascriptjqueryhtmlhref

Cancel the href case that not all the values filled


I have a function that checks if the values ​​are filled by pressing the button, if not all complete I want to cancel the href of the button.

I tried this:

<a href="XXX.html"  data-role="button" data-transition="none"
                data-theme="b" onclick="Check(); return false;" data-icon="forward" data-iconpos="left">
            </a>

And also tried to return false from the function.

Both ways do not work!

Which is another way I can cancel the href?

I tried these things:

function Check(event) {

    if (Testing the values ​​filled) {
     //Do something
    }
    else {
//One of the two following lines
        event.preventDefault();
        $("#xxx .ui-btn").unbind('click');
    }

}

Even those things do not work, he comes to else but it does not cancel the href


Solution

  • I solved the problem as follows:

    function Check() {
      if (Testing the values ​​filled) {
       //Do something
      }
      else {
       $("#xxx .ui-btn").attr('href', "javascript:void(0)");
      }
    

    Thank you all for the help