Nu vet jag inte om det är i rätt forum, tycker ni jag är fel så flytta mig rätt.
Jo, xhtml-strict tillåter ju inte name="fName", men jag måste ha det på mitt formulär för att kunna validera det med javascript.
Att bara byta till id="fName" gör att sidan valideras ok som xhtml-strict, men det hjälper inte mig då anropet till valideringsfunktionen i javascript orsakar felmeddelande.
Kan man lösa detta på något sätt genom att ändra i javascript-funktionen så jag kan använda id istället för name ?
Hmm, jo jag har försökt med det men får inte till det..
Mitt formulär:
<form action="default.asp?catid=send" method="post" id="pk" onsubmit="return validateForm();">
<!-- Några textfält mm. se nedan. -->
</form>
Min funktion ser ut så här nu:
function validateForm(){
if (document.pk.txName.value==""){
alert("Du har inte angett ditt namn.");
document.pk.txName.style.backgroundColor='#CC9999';
document.pk.txMail.style.backgroundColor='#f0f0f0';
document.pk.txTele.style.backgroundColor='#f0f0f0';
document.pk.txMsg.style.backgroundColor='#f0f0f0';
document.pk.txName.focus();
return false;
} else if (document.pk.txMail.value.indexOf("@") == -1){
alert("Du har inte angett en korrekt mailadress.");
document.pk.txName.style.backgroundColor='#f0f0f0';
document.pk.txMail.style.backgroundColor='#CC9999';
document.pk.txTele.style.backgroundColor='#f0f0f0';
document.pk.txMsg.style.backgroundColor='#f0f0f0';
document.pk.txMail.focus();
return false;
} else if (document.pk.txTele.value==""){
alert("Du har inte angett ditt telefonnummer.");
document.pk.txName.style.backgroundColor='#f0f0f0';
document.pk.txMail.style.backgroundColor='#f0f0f0';
document.pk.txTele.style.backgroundColor='#CC9999';
document.pk.txMsg.style.backgroundColor='#f0f0f0';
document.pk.txTele.focus();
return false;
} else if (document.pk.txMsg.value==""){
alert("Du har inte angett något meddelande.");
document.pk.txName.style.backgroundColor='#f0f0f0';
document.pk.txMail.style.backgroundColor='#f0f0f0';
document.pk.txTele.style.backgroundColor='#f0f0f0';
document.pk.txMsg.style.backgroundColor='#CC9999';
document.pk.txMsg.focus();
return false;
}
}
function validateForm(){
if (document.getElementById("txName").value==""){
alert("Du har inte angett ditt namn.");
document.getElementById("txName").style.backgroundColor='#CC9999';
document.getElementById("txMail").style.backgroundColor='#f0f0f0';
document.getElementById("txTele").style.backgroundColor='#f0f0f0';
document.getElementById("txMsg").style.backgroundColor='#f0f0f0';
document.getElementById("txName").focus();
return false;
} else if (document.getElementById("txMail").value.indexOf("@") == -1){
alert("Du har inte angett en korrekt mailadress.");
document.getElementById("txName").style.backgroundColor='#f0f0f0';
document.getElementById("txMail").style.backgroundColor='#CC9999';
document.getElementById("txTele").style.backgroundColor='#f0f0f0';
document.getElementById("txMsg").style.backgroundColor='#f0f0f0';
document.getElementById("txMail").focus();
return false;
} else if (document.getElementById("txTele").value==""){
alert("Du har inte angett ditt telefonnummer.");
document.getElementById("txName").style.backgroundColor='#f0f0f0';
document.getElementById("txMail").style.backgroundColor='#f0f0f0';
document.getElementById("txTele").style.backgroundColor='#CC9999';
document.getElementById("txMsg").style.backgroundColor='#f0f0f0';
document.getElementById("txTele").focus();
return false;
} else if (document.getElementById("txMsg").value==""){
alert("Du har inte angett något meddelande.");
document.getElementById("txName").style.backgroundColor='#f0f0f0';
document.getElementById("txMail").style.backgroundColor='#f0f0f0';
document.getElementById("txTele").style.backgroundColor='#f0f0f0';
document.getElementById("txMsg").style.backgroundColor='#CC9999';
document.getElementById("txMsg").focus();
return false;
}
}
260 ms totalt · 4 externa anrop · v20260731065814-full.c32e866c