Announcement

Collapse
No announcement yet.

Jquery Funktion return Variable

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Jquery Funktion return Variable

    Hallo zusammen,

    ich möchte aus einer Jquery Funktion eine Variable übergeben. Das ist die Funktion, darin soll einfach geprüft werden ob eine PLZ
    gültig ist. Dazu übergebe ich die PLZ, Land und Typ (KD = PLZ der Rechnungsadresse, LS = PLZ Lieferanschrift ).

    Wenn die PLZ ok ist soll send_ok = 1 sein.

    PHP Code:
    $.fn.checkPLZ = function (plzlandtyp) {
        var 
    typ;
        var 
    send_ok 0;
        $.
    ajax({
          
    type"POST",
          
    asynctrue,
          
    url"/templates/tpl_chk_plz.php",
          
    data: { plzplzlandland},
          
    success: function (data) {
            
    data jQuery.parseJSON(data);
            var 
    plz_ok data[0].plz;
            if(
    plz_ok == 0) {

              if(
    typ == 'KD') {
                $(
    "#kunden_plz").css({background"#ffd1d1"});
                $(
    "#kunden_plz").focus();
              }
              else if(
    typ == 'LS'){
                $(
    "#liefer_plz").css({background"#ffd1d1"});
                $(
    "#liefer_plz").focus();
              }
              $(
    "#anzMsgTxt").text("Bitte prüfen Sie die eingegebene PLZ!");
              $(
    document).alertMsg();
              
    e.preventDefault();
            }
            else
            {
              return 
    send_ok 1;
            }
          },
        });
      }; 
    Wenn ich mir die Variable ausgeben lasse steht da "undefined".

    Wie kann ich die Variable übergeben?

    Danke

  • #2
    jQuery.fn.myFunction = function() {
    return 500;
    };

    alert($('div').myFunction());

    bekomme 500 angezeigt
    Christian

    Comment


    • #3
      Bekomme ich irgendwie nicht hin. Ich habe das mal vereinfacht:

      PHP Code:
      $.fn.checkPLZ = function (plzland) {
          var 
      send_ok = $.ajax({
          
      type"POST",
          
      asynctrue,
          
      url"/templates/tpl_chk_plz.php",
          
      data: { plzplzlandland},
          
      success: function (data) {
            
      data jQuery.parseJSON(data);
            var 
      plz_ok data[0].plz;
            return 
      plz_ok;
          },
        });
      }; 
      Die Funktion bringt 0 oder 1 als Ergebnis, das brauche ich in einer Variablen

      PHP Code:

      var isplzok = $(document).checkPLZ(plz,land); 

      Wie bekomme ich mein Ergebnis in die Variable isplzok?

      Comment

      Working...
      X