Click here to Skip to main content
15,905,004 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I clear the validation message displayed as text in the page. Code is given below:
function resettextbox()
{
	
	document.getElementById("spnFirstName").innerHTML=null;
	document.getElementById("spnSecondName").innerHTML=null;
	document.getElementById("frm1").reset();
}

XML
<html>
<body>
<script type="text/javascript" src="External.js">
</script>
<form id="frm1" method="get">
<table>
<tr>
     <td>First Name: <input type="textbox" id="FirstName"/></td>
     <td>Second Name:<input type="textbox" id="SecondName"/></td>
    <td><input type="button" value="Submit" onClick="return validation()"/></td>
     <td><input type="button" value="Reset"  onClick="reset()"/></td>
</tr>
<tr>
     <td><span id="spnFirstName" span style=color:red></span></td>
     <td><span id="spnSecondName" span style=color:red></span></td>
</tr>
</table>
</form>
</body>
</html>
Posted
Updated 13-Jan-11 22:04pm
v2
Comments
JF2015 14-Jan-11 4:04am    
Edited to fix code formatting.

Take a look at this article:
Multiple Fields Validator - An ASP.NET Validation Control[^]

It's probably one of the easier solutions your problem, and the implementation is fairly robust.

Regards
Espen Harlinn
 
Share this answer
 
If you just want to clear the contents of the span, use this code:

document.getElementById("spnFirstName").innerHTML = '';


If you want to hide the span, use the following code:

document.getElementById("spnFirstName").style.display = '';


I am adding code to show some demonstration:

Use the following Java Script:
C#
function resettextbox(val) {
    document.getElementById("spnFirstName").innerHTML = val;
    document.getElementById("spnSecondName").innerHTML = val;
}
function showhidetextbox(val) {
    document.getElementById("spnFirstName").style.display = val;
    document.getElementById("spnSecondName").style.display = val;
}


Use the following aspx code:
XML
<div>
    <input type="button" value="HIDE" onclick="showhidetextbox('none');" />
    <input type="button" value="Show" onclick="showhidetextbox('');" />
    <input type="button" value="Clear" onclick="resettextbox('');" />
    <input type="button" value="Set" onclick="resettextbox('Value');" />
    <span id="spnFirstName" style="color: red">1</span>
    <span id="spnSecondName" style="color: red">2</span>
</div>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900