Witam! Otóż mam formularz wzbogacony o JS. I pojawia sie taki problem, gdy po kliknięciu przycisku 'wyślij' (jeżeli sie nie wprowadziło danych, bądz chociazby 1 pola sie nie wypełniło) to pojawiał sie alert ze trzeba wypełnic. I ok. Dalej wciskam ok i tu problem. Skrypt leci dalej i uruchamia plik action="plik.php". A chodzi mi oto, żeby właśnie powróciło do formularza, po kliknięciu OK. Natomias jeżeli jest zwykły link to działa tak jak powinno. Problem pojawia sie, gdy zamiast linka do potwierdzenia/wysłania jest <input>.Z góry dzieki i pozdrawiam!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" href="style.css" type="text/css" media="screen" /> <script type="text/javascript"> function $(id){
return document.getElementById(id);
}
function check(){
var wyslij = 1;
var pola = '';
if(!($("nick").value)){
$("nick").style.border = '1px solid Red';
pola += ' Nick';
wyslij = 0;
}
else $("nick").style.border = '1px solid Black';
if(!($("mail").value)){
$("mail").style.border = '1px solid Red';
pola += ', E-mail';
wyslij = 0;
}
else $("mail").style.border = '1px solid Black';
if(!($("tresc").value)){
$("tresc").style.border = '1px solid Red';
pola += ', Treść';
wyslij = 0;
}
else $("tresc").style.border = '1px solid Black';
if(wyslij) $("formularz").sent();
else alert('Wypenij pola: '+pola);
}
<form id="formularz" method="post" action="wyslij.php"> <input id="nick" name="nick" class="text" type="text" /> <input id="mail" name="mail" class="text" type="text" /> <input id="submit" name="submit" class="submit" type="submit" value="Wyślij" onclick="check();"/>
Ten post edytował ens0re 11.08.2006, 23:34:50