Tuesday, 15 March 2011

php - Dont understand where and how to put javascript block change page -



php - Dont understand where and how to put javascript block change page -

i have notification page (page before going register page) page check info database, if false / true show message under textbox, show message not block process input. 1 notification page (show true message if check.php no conflic):

<head> <script src="js/jquery.js" type="text/javascript"></script> <script src="js/settings.js" type="text/javascript"></script> <script type="text/javascript"> pic1 = new image(16, 16); pic1.src = "img/loader.gif"; //untuk nim $(document).ready(function(){ $("#cekintern").change(function() { var nomor = $("#cekintern").val(); if(nomor.length >= 8) { $("#status2").html('<img src="img/loader.gif" align="absmiddle">&nbsp;checking availability...'); $.ajax({ type: "post", url: "check.php", data: "cekintern="+ nomor, success: function(msg){ $("#status2").ajaxcomplete(function(event, request, settings){ if(msg == 'ok') { $("#cekintern").removeclass('object_error'); // if necessary $("#cekintern").addclass("object_ok"); $(this).html('&nbsp;<img src="img/accepted.png" align="absmiddle"> <font color="green"> available </font> '); } else { $("#cekintern").removeclass('object_ok'); // if necessary $("#cekintern").addclass("object_error"); $(this).html(msg); } }); } }); } else { $("#status2").html('&nbsp;<img src="img/decline.jpg" align="absmiddle"> <font color="red">maaf nim anda salah.</font>'); $("#cekintern").removeclass('object_ok'); // if necessary $("#cekintern").addclass("object_error"); alert('maaf nim salah!!'); window.location.href='?get=2'; } }); }); //--> </script> </head> <body><br /> <form name="form1" method="post" action="register.php"> <center> <em>input <strong>nim</strong></em><br /> <input name="cekintern" type="text" id="cekintern" size="15" maxlength="9" placeholder="input nim here"/><div id="status2"></div><br /> <input type="submit" value="confirm" /> <input type="button" name="button" id="button" value="cancel" onclick="window.location='index.php'"/></center> </form>

and 1 check.php check database , show message error if has conflic:

<?php if(isset($_post['cekintern'])) { $nimintern = $_post['cekintern']; $sql_check = mysql_query("select * {$prefix}intern nim='$nimintern'"); if(mysql_num_rows($sql_check)) { $nimintern = $_post['cekintern']; $sql_check2 = mysql_query("select * {$prefix}pengguna nim_pengguna='$nimintern'"); if(mysql_num_rows($sql_check2)) { echo '&nbsp;<img src="img/decline.jpg" align="absmiddle"> <font color="red">maaf nim <strong>'.$nim.'</strong> nim anda sudah terdaftar.</font>'; homecoming false; } else { echo 'ok'; }} else { echo '&nbsp;<img src="img/decline.jpg" align="absmiddle"> <font color="red">maaf nim <strong>'.$nim.'</strong> tidak ada dalam daftar mahasiswa.</font>'; homecoming false; }} ?>

all message works, im confuse should write create notification.php (javascrit) & check.php (php) cancel input if message has conflic.

you have code in succes ajax callback, can add together 1 instruction if conflict :

$("#status2").ajaxcomplete(function(event, request, settings){ if(msg == 'ok') { $("#cekintern").removeclass('object_error'); // if necessary $("#cekintern").addclass("object_ok"); $(this).html('&nbsp;<img src="img/accepted.png" align="absmiddle"> <font color="green"> available </font> '); } else { $("#cekintern").removeclass('object_ok'); // if necessary $("#cekintern").addclass("object_error"); $(this).html(msg); $("#cekintern").val("");/******/ }

php javascript block

No comments:

Post a Comment