25. december 2001 - 12:19Der er
3 kommentarer og 1 løsning
Formvalidering?
Jeg har fundet dette script her på eksperten:
************* SNIP **************** function checkForm(frmName) { for (i = 0; i < document.frmName.elements.length; i++) { var which = document.frmName.elements[i]; var alertMsg = \"You must fill out all the mandatory fields\";
if (which.type == \"text\") { if (which.value == \"\") { alert(alertMsg); which.focus(); return false; } } else if (which.type == \"textarea\") { if (which.value == \"\") { alert(alertMsg); which.focus(); return false; } } else if (which.type == \"select-one\") { if (which.options.selectedIndex == -1) { alert(alertMsg); which.focus(); return false; } } else if (which.type == \"select-multiple\") { if (which.options.selectedIndex == -1) { alert(alertMsg); which.focus(); return false; } } } return true; } ****************** SNIP ********************
Min Form-tag er som følger: <form name=\"frmLitteraturStep1\" method=\"post\" action=\"litteratur.asp?action=step1\" onSubmit=\"return checkForm(this);\">
Dette giver mig fejlen: \"document.frmName is null or not an object\" (tror jeg nok det hedder)
Den bruger altså ikke variablen/argumentet...why? (Scriptet ligger i en fil som includes (include file=\"xx\") i alle filer med forms.
function checkForm(frmLitteraturStep1) { for (i = 0; i < document.frmName.elements.length; i++) { var which = document.frmName.elements[i]; var alertMsg = \"You must fill out all the mandatory fields\";
if (which.type == \"text\") { if (which.value == \"\") { alert(alertMsg); which.focus(); return false; } } else if (which.type == \"textarea\") { if (which.value == \"\") { alert(alertMsg); which.focus(); return false; } } else if (which.type == \"select-one\") { if (which.options.selectedIndex == -1) { alert(alertMsg); which.focus(); return false; } } else if (which.type == \"select-multiple\") { if (which.options.selectedIndex == -1) { alert(alertMsg); which.focus(); return false; } } } return true; }
Synes godt om
Slettet bruger
25. december 2001 - 12:36#3
Dit første forslag duer ikke, eftersom det er til 10 forskellige forms, med forskelligt indhold - hvilket også udelukker dit andetr forslag :o/ sorry
Synes godt om
Slettet bruger
25. december 2001 - 14:01#4
Jeg omskrev ovenstående til at være baseret på formens index (forms[index]) i stedet - og så fungerede det...
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.