<html>
<head>
<script type="text/javascript">
function checkName(input)
{
if(input.length >= 5)
{
document.getElementById('nameRed').innerHTML = "test";
}
else
{
document.getElementById('nameRed').style.display = 'none';
}
}
</script>
<style type="text/css">
#nameRed{display: none;color:red;}
</style>
</head>
<body>
<input type="text" size="20px" id="name" onBlur="checkName(this.value)" />
<div id="nameRed"></div>
</body>
</html>
3 replies to this topic
#1
Posted 14 June 2011 - 08:49 AM
Can I use innerHTML on blur? This doesn't seem to be working for some reason but if I use anything else with this onblur it works fine. Any suggestions?
|
|
|
#2
Posted 14 June 2011 - 12:28 PM
use this :)
your only problem was that you were not making it visible (plus the fact you missed the "=" after onBlur
also, onBlur only takes effect after the user has finished typing and clicks somewhere else on the page, onKeyUp runs the function after every button pressed
<html>
<head>
<script type="text/javascript">
function checkName(input)
{
if(input.length >= 5)
{
document.getElementById('nameRed').innerHTML = "test";
document.getElementById('nameRed').style.display = 'block';
}
else
{
document.getElementById('nameRed').style.display = 'none';
}
}
</script>
<style type="text/css">
#nameRed{display: none;color:red ;}
</style>
</head>
<body>
<input type="text" size="20px" id="name" onKeyUp="checkName(this.value)" />
<div id="nameRed"></div>
</body>
</html>
your only problem was that you were not making it visible (plus the fact you missed the "=" after onBlur
also, onBlur only takes effect after the user has finished typing and clicks somewhere else on the page, onKeyUp runs the function after every button pressed
Edited by TheFedGuy, 14 June 2011 - 04:21 PM.
#3
Posted 15 June 2011 - 04:20 AM
This code works, your div just is invisble so you don't see anything.
add
add
document.getElementById('nameRed').style.display = 'block';
After changing the innerhtml.
Edited by wim DC, 15 June 2011 - 11:16 PM.
#4
Posted 15 June 2011 - 07:16 AM
:S wow im an idiot. Thanks !
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









