-1

I've a very simple question, but I can't find the correct way to resolve. I have a phonegap app wich has a login, and I check the results with ajax. I check the form when the user click:

<a href="home.html" data-transition="pop">GO</a>

The order of the instructions are: 1- The user clik GO. 2- Check the form inputs. 3- IF they'e corrects, go home.html

I can't do a

window.location.replace('index.html');

because I lost the data-transition.

Another option could be make a link hidden, and trigger his click when necesary, but I dont like it.

The best way it's when click at Go, do something, and if It's necesary go to his href.

Thanks for all !

3 Answers3

1

You could implement an onclick function and do preventDefault if the conditions for progressing to the link url aren't fulfilled. Have a look at this question:

preventDefault inside onclick attribute of a tag

Community
  • 1
  • 1
andrrs
  • 2,289
  • 3
  • 17
  • 25
1
$("a").click(function(e){

    // Do what all checks you need to do here
    if(something is wrong)
    {
        // Do stuff here
        e.preventDefault(); // Stop propagation of default event.
        return false;
    }  

});

This way the data-transition will also work, becaue the default event will be stopped only when the validation fails.

void
  • 36,090
  • 8
  • 62
  • 107
1

If you are using ajax, then why dont you return 'true' or 'false' value depending upon the validation result that you are performing.

Then in your 'success function' of ajax, you can check if the result is 'true' or 'false', and if validations are 'true', you can use window.location.href method of javascript.

Ajit Kumar Singh
  • 357
  • 2
  • 11