Działa on tak że gdy wszystko się zgadza wysyła formularz submit();
Kod
<script LANGUAGE="JavaScript">
<!-- Begin
extArray = new Array(".inc", ".jpg", ".gif"); // TABLICA Z ROZSZERZENIAMI PLIKOW KTORE MAJA BYC AKCEPTOWANE DO WYSLANIA
function LimitAttach(form, file)
{
allowSubmit = false;
if (!file) return;
while (file.indexOf("\\\") != -1)
file = file.slice(file.indexOf("\\\") + 1);
ext = file.slice(file.indexOf(".")).toLowerCase();
for (var i = 0; i < extArray.length; i++) {
if (extArray[i] == ext) { allowSubmit = true; break; }
}
if (allowSubmit) form.submit();
else
alert("Proszę wysyłać tylko pliki graficzne typu: "
+ (extArray.join(" ")) + "\nProsze wybrać nowy plik "
+ "i wysłać ponownie.");
}
// End -->
</script>
<form enctype="multipart/form-data" action="upload.php" method="POST" name="form" >
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input name="userfile" type="file" />
<input type=button value="Wyślij" onclick="LimitAttach(this.form, this.form.userfile.value)" />
</form>
<!-- Begin
extArray = new Array(".inc", ".jpg", ".gif"); // TABLICA Z ROZSZERZENIAMI PLIKOW KTORE MAJA BYC AKCEPTOWANE DO WYSLANIA
function LimitAttach(form, file)
{
allowSubmit = false;
if (!file) return;
while (file.indexOf("\\\") != -1)
file = file.slice(file.indexOf("\\\") + 1);
ext = file.slice(file.indexOf(".")).toLowerCase();
for (var i = 0; i < extArray.length; i++) {
if (extArray[i] == ext) { allowSubmit = true; break; }
}
if (allowSubmit) form.submit();
else
alert("Proszę wysyłać tylko pliki graficzne typu: "
+ (extArray.join(" ")) + "\nProsze wybrać nowy plik "
+ "i wysłać ponownie.");
}
// End -->
</script>
<form enctype="multipart/form-data" action="upload.php" method="POST" name="form" >
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input name="userfile" type="file" />
<input type=button value="Wyślij" onclick="LimitAttach(this.form, this.form.userfile.value)" />
</form>
Jak podpiąć skrypt do tego skryptu:
Kod
<script language="JavaScript" type="text/javascript">
<!--
function checkForm() {
formErrors = false;
if (document.rejestruj.haslo1.value != document.rejestruj.haslo2.value) {
formErrors = "Hasło i hasło powtórzone nie są takie same!";
}
if (document.rejestruj.haslo1.value.length < 5) {
formErrors = "Hasło musi mieć minimum 5 znaków";
}
if (formErrors) {
alert(formErrors);
return false;
}
}
//-->
</script>
<br><br>
<form method="POST" name="rejestruj" enctype="multipart/form-data" onsubmit="return checkForm(this)" action="">
Hasło: <input class="pole" type="password" value="haslo1" name="haslo1" size="20">
<br><br>
Powtórz hasło: <input class="pole" type="password" value="haslo2" name="haslo2" size="20">
<br><Br>
Avatar: <input type="hidden" name="MAX_FILE_SIZE" value="99999999"><input class="pole" type="file" name="avatar" size="21"><br><Br>
<input type="submit" name="go" value="Rejestracja">
</form>
<!--
function checkForm() {
formErrors = false;
if (document.rejestruj.haslo1.value != document.rejestruj.haslo2.value) {
formErrors = "Hasło i hasło powtórzone nie są takie same!";
}
if (document.rejestruj.haslo1.value.length < 5) {
formErrors = "Hasło musi mieć minimum 5 znaków";
}
if (formErrors) {
alert(formErrors);
return false;
}
}
//-->
</script>
<br><br>
<form method="POST" name="rejestruj" enctype="multipart/form-data" onsubmit="return checkForm(this)" action="">
Hasło: <input class="pole" type="password" value="haslo1" name="haslo1" size="20">
<br><br>
Powtórz hasło: <input class="pole" type="password" value="haslo2" name="haslo2" size="20">
<br><Br>
Avatar: <input type="hidden" name="MAX_FILE_SIZE" value="99999999"><input class="pole" type="file" name="avatar" size="21"><br><Br>
<input type="submit" name="go" value="Rejestracja">
</form>
Albo odwrotnie .... chodzi mi aby połaczyć oba te skrypty tak żeby sprawdzały formularz. i żeby wszystko działało

Ale najlepiej by było żeby był button type="submit" a nie type="button"
Chyba wszystko jasno wytłumaczyłem.