0

I have one form for validating a user, now I'm testing and need give 2 clicks for send, I read in many forums but can not find the solution to my problem.

This is the script code:

<script>
    $(function () {
        $('#enviar').click( function() {
                   if($('#correo').val().length > 0 && $('#pwd').val().length > 0){
                       var pwd2 = MD5($('#pwd').val());

                       var myData = "correo="+$('#correo').val()+"&pwd="+pwd2;
                        $.ajax({
                            type: "POST",
                             url:"http://myurlthatisworkingfine/registro/login",
                             data: myData,
                             dataType: 'json', // Notice! JSONP <-- P (lowercase)
                             success: function(data) {
                                        alert(data.message);
                                    }
                             },
                             error:function(){
                                 alert("Error");
                             }      
                        });
                    } else {
                            alert('Por favor, rellena los dos campos');
                            }          
                    return false;
          });
    }); 

</script>

The form:

<form id="check-user" data-ajax="false">
            <fieldset>
                <div data-role="fieldcontain">
                    <label> Usuario </label>
                    <input type="text" id="correo" name="correo">
                </div>
                <div data-role="fieldcontain">
                    <label> Contrase&ntilde;a </label>
                    <input type="password" id="pwd" name="pwd" >
                </div>
                <input type="submit" data-role="button" value="Acceder" name="enviar" id="enviar">

                <a href="pasword.html" data-role="button" data-icon="home" data-theme="a">He olvidado mi contrase&ntilde;a</a>
            </fieldset>
        </form>

All works very fine the only problem it´s with submit , i need 2 times for send the form finally. How can I fix this?

Joel
  • 4,732
  • 9
  • 39
  • 54
amejia13
  • 11
  • 3
  • 1
    Are you getting any errors on the first click? – putvande Jun 30 '14 at 16:06
  • That makes no sense, you always return false, that form should **never** submit. – Liam Jun 30 '14 at 16:08
  • Also see [How to return the response from an Ajax call?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call) – Liam Jun 30 '14 at 16:09
  • @Liam It does submit, via AJAX. – putvande Jun 30 '14 at 16:10
  • Are you sure there is only one AJAX call being sent? Based on the code and from your comment, there should be 2 AJAX req sent. – Veera Jun 30 '14 at 16:10
  • I have no error in the first submit, only charge the page. I think i have only one ajax call... All work fine but I need click one time before... – amejia13 Jun 30 '14 at 16:17
  • are you sure about the syntax? I can see a syntax error in the ajax block, *an additional closing curly brace* after success callback. – code-jaff Jun 30 '14 at 16:55
  • I have reviewed all the code and it seems they are all closed – amejia13 Jun 30 '14 at 17:08

1 Answers1

0
  <div data-role="fieldcontain">
        <fieldset data-role="controlgroup">     
                <input type="radio" name="" id="inputID1" value=""  />
                <label for="inputID1">LabelText...</label>

                <input type="radio" name="" id="inputID2" value=""  />
                <label for="inputIDd">LabelText2...</label>

                <!-- .. more inputs maybe ..-->
       </fieldset>
   </div> 

I am pretty sure your div data-role="fieldcontain" && fieldset data-role="controlgroup" is the wrong way around. Try to do your html part as shown in my example above. So dont give every input a data-role="fieldcontain" itself..

Jquery mobile has some problem to get the clicks on a inputs especially radio buttons. But if you mark it this way, it should work just fine. ( it did on my project )

Hope that helped...

Phil LA
  • 163
  • 1
  • 2
  • 10
  • But I need write in the inputs the mail and password. If I do like you say I cannot get this information... – amejia13 Jun 30 '14 at 16:34
  • Sorry i dont get your problem. I don´t know if improving your html markup will help you on your problem with the 2 clicks but i see a big change of doing though. You can get the informations just as usual $('passwordID').val();, whats the problem? ______ as well as your form probably submits because of the input type="submit" and the .click event on the button... but i dont know your code so its just a guess.. – Phil LA Jun 30 '14 at 16:49