Problem jest taki, że jak daje na samym końcu funkcji submitchecker
alert('TICK to: ' + ajax_checker(parseInt(document.cart.quantity.value), document.cart.code0.value, document.cart.code1.value, document.cart.code2.value, document.cart.code3.value, document.cart.code4.value));
to dostaje cały czas undefined
function ajax_checker(quantity_value, code0, code1, code2, code3, code4) {
$.post("js/ajax_checker.php",{checker:quantity_value, code0:code0, code1:code1, code2:code2, code3:code3, code4:code4}, function(data) {
if (data) return false;
else return true;
});
}
function submitchecker()
{
//wartości przesyłane do funkcji są poprawne, sprawdzane alertem
if (ajax_checker(parseInt(document.cart.quantity.value), document.cart.code0.value, document.cart.code1.value, document.cart.code2.value, document.cart.code3.value, document.cart.code4.value)) document.cart.submit();
else alert("Pola wymagane musza być zaznaczone i miec poprawna wartosc!");
}
Na formularzu jest:
[/php]
//ten plik jest raczej ok bo jak go wywołuję ręcznie z parametrami to zwraca poprawne wartości, czyli wyświetla nic lub coś w przypadku błędnych danych
[php]
$marker = FALSE;
//database connection
//code check
$checker = trim($_REQUEST['checker']); //wartośc pola quantity $code0 = trim($_REQUEST['code0']); $code1 = trim($_REQUEST['code1']); $code2 = trim($_REQUEST['code2']); $code3 = trim($_REQUEST['code3']); $code4 = trim($_REQUEST['code4']);
//quantity check
for ($i=0; $i<5; $i++) {
$code = trim($_REQUEST['code'.$i]); $countable += mysql_num_rows(mysql_query("SELECT id FROM grupon WHERE product_id=4 AND checker=0 AND code= BINARY '$code'")); }
$grupon_counter = mysql_num_rows(mysql_query("SELECT id FROM grupon WHERE checker=0 AND code=BINARY '$code0' OR code=BINARY '$code1' OR code=BINARY'$code2' OR code=BINARY'$code3' OR code=BINARY'$code4'"));
if ($grupon_counter && $checker == $countable) $marker = TRUE; //check if the useful code is in DB
if ($marker) {} //if it is print nothing
else echo 'Kod ' .$checker. ' jest niepoprawny lub został już użyty'; //it it isnt print error massege
Plik z formularzem
<img id="submit_button" onClick="submitchecker();" src="layout/1/cart_order_off.png">
Ten post edytował amii 19.10.2011, 11:03:53