Cant make JSON/PHP echo message appear using jQuery -


i'm trying make php echo messages show whenever users inputs either nothing @ or no numbers. ive been able make error messages show when doesnt input numbers onto text field.

however cant make error message i've created in php show whenever clicks send button without inputing @ in text field.

my php code:

$resurs    = array(); $fyll = $_get['inputfield']; $dg = 2;  $nummer1      = $nummer1 * $dg; $fel = "fill in number"; $nummer2      = $nummer1 * $fill; $no = "field empty";  if (is_numeric($fyll)){  $resurs = array(     "nummer1" => $nummer1. "<br>",     "nummer2" => $nummer2. "<br>"  );  echo json_encode($resurs);      }  else {     $resurs = array (     "fel" => $fel. "<br>"     );  echo json_encode ($resurs); }            if (empty($fyll)){     $resurs = array (     "no" => $no. "<br>"     );      echo json_encode ($resurs); } 

my jquery:

$(document).ready(function(){     $("#submit1").click(function(){     var siffra = document.getelementbyid("inputfield");         $.getjson("form.php?inputfield="+siffra.value, function(result){ var t1; var t2; var t3; var error;                      $.each(result, function(i, field){                  if (i =="nummer1"){                 t1 = field                 }                  if (i == "nummer2"){                 t2 = field                 }                  if (i == "no"){                 t3 = field                 }                  if (i == "fel"){                 error = field                 }                                $(".d1").html(t1);                 $(".d2").html(t2);                 $(".d3").html(t3);                 $(".d3").html(error);             });          });     }); }); 

field object. need retrieve properties of object. either, field.nummer1, field.nummer2, field.fel or field.no depending on response request. try this:

$.each(result, function (i, field) {     if (i == "nummer1")         t1 = field.nummer1;      if (i == "nummer2")         t2 = field.nummer2;      if (i == "no")         t3 = field.no;      if (i == "fel")         error = field.fel;      $(".d1").html(t1);     $(".d2").html(t2);     $(".d3").html(t3);     $(".d3").html(error); }); 

note you're setting value of each .dx element in each iteration of loop, when there no value variable provided. suggest check logic of function against requirements.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -