small jquery problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pradeepjain
    Contributor
    • Jul 2007
    • 563

    small jquery problem

    i am building a select based on the values in a text box .
    like

    Code:
    $("#pincode").change(function(){
    $.post("doctor_search.php",{ pincode:$("#pincode").val()} ,function(data){
    $("#suggestions").html(data);
    });
        });
    when ever a error occurs when the form is submitted the select does not work as ajax is a change function . how to say to jquery tht do it if the value in the text box is not null also i.e trigger a event ??
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Why not add a simple if condition which checks the value? If it's not empty. the request is made.

    Comment

    • pradeepjain
      Contributor
      • Jul 2007
      • 563

      #3
      hmm..yeah i thought of same logic..but i cld not write the if condition in jquery !! i am new to it !plzz can u show me the code !!only if condition?

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Why not use regular JavaScript, except perhaps to reference an element? E.g.
        Code:
        if ($("#pincode").val() != "") {

        Comment

        • pradeepjain
          Contributor
          • Jul 2007
          • 563

          #5
          its something like this rite

          Code:
          if ($("#pincode").val() != "") {
          $("#pincode").change(function(){
          $.post("doctor_search.php",{ pincode:$("#pincode").val()} ,function(data){
          $("#suggestions").html(data);
          });
              });
          }

          I had written that code earlier only ! but did not work ! so i thought the code was wrong ! anyways will give it a try again and get back to you. thank you :)

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            No, that's not correct. Put the if statement inside the change function.

            Comment

            • pradeepjain
              Contributor
              • Jul 2007
              • 563

              #7
              but then error is other fields are discovered and errors are displayed again bcos of the
              Code:
              .change
              i need to change the value in the pincode field for the jquery event to happen !!

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                So you want this to take place when the form is submitted even if there are errors?

                Comment

                • pradeepjain
                  Contributor
                  • Jul 2007
                  • 563

                  #9
                  if the field has some value in it the event must be triggered !

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    Yes, but when? When should the check be made that there's some text in the field?

                    Comment

                    • pradeepjain
                      Contributor
                      • Jul 2007
                      • 563

                      #11
                      when the user fills out the form 1st time its all okie .he fills the pincode thing so .change will work there . but say when the form has some errors and the same page is displayed with errors then the .change will not happen so i wanted to check if value is there in pincode then trigger the event !

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        When the same page is displayed with errors, is the page still the same (Ajax) or what it unloaded/reloaded?

                        I think it's best if you show the page where the problem occurs.

                        Comment

                        Working...