do not use "document.write", use some other means like hiddent content and inserting html code with insertAdjacentHTML or innerHTML, here is an example, also see my response to your other post:<style type="text/css">
FORM SPAN {color:red;}
</style>
<form name="frmtest" onsubmit="return checkInput()">
<div id="dvPrompt">Enter the following fields:</div>
Field 1:<input type="text" name="txt1"><br>
Field 2:<input type="text" name="txt2"><br>
<input type="submit" value="Submit">
</form>
<script language="javascript">
function checkInput()
{
var elements = document.frmtest.elements;
var nErr = 0;
for (var i=0; i < elements.length;i++)
{
if (elements[i].type != "button" && elements[i].type != "submit" && elements[i].type != "reset")
if (elements[i].value.length == 0)
{
if (elements[i].nextSibling.tagName != "SPAN")
{
elements[i].insertAdjacentHTML("afterEnd","<span>*</span>");
} elements[i].nextSibling.style.display="";
++nErr;
}
else
{
if (elements[i].nextSibling.tagName == "SPAN")
{
elements[i].nextSibling.style.display="none";
}
}
} if (nErr > 0)
{
document.all("dvPrompt").innerHTML = "Please enter a valid value for fields with <span>*</span>:";
return false;
}
return true;
}
</script>
FORM SPAN {color:red;}
</style>
<form name="frmtest" onsubmit="return checkInput()">
<div id="dvPrompt">Enter the following fields:</div>
Field 1:<input type="text" name="txt1"><br>
Field 2:<input type="text" name="txt2"><br>
<input type="submit" value="Submit">
</form>
<script language="javascript">
function checkInput()
{
var elements = document.frmtest.elements;
var nErr = 0;
for (var i=0; i < elements.length;i++)
{
if (elements[i].type != "button" && elements[i].type != "submit" && elements[i].type != "reset")
if (elements[i].value.length == 0)
{
if (elements[i].nextSibling.tagName != "SPAN")
{
elements[i].insertAdjacentHTML("afterEnd","<span>*</span>");
} elements[i].nextSibling.style.display="";
++nErr;
}
else
{
if (elements[i].nextSibling.tagName == "SPAN")
{
elements[i].nextSibling.style.display="none";
}
}
} if (nErr > 0)
{
document.all("dvPrompt").innerHTML = "Please enter a valid value for fields with <span>*</span>:";
return false;
}
return true;
}
</script>
with some error input, the indicative information can only be displayed for one
second and then disappear.I change the button type to "button" and then it is ok. I think I cannot prevent the form from being submitted. How to deal with this relasionship between checking and submitting,could you tell me? I will be
very appreciated!
of the CheckInput() function. Thank you very much and sorry for bothering
you too much.