Jump to content

Dynamic Form Validation

- - - - -

  • Please log in to reply
3 replies to this topic

#1
Howdy_McGee

Howdy_McGee

    Programmer

  • Members
  • PipPipPipPip
  • 135 posts
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?


<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>



#2
TheFedGuy

TheFedGuy

    Newbie

  • Members
  • Pip
  • 3 posts
use this :)

<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
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
This code works, your div just is invisble so you don't see anything.
add
document.getElementById('nameRed').style.display = 'block';
After changing the innerhtml.

Edited by wim DC, 15 June 2011 - 11:16 PM.


#4
Howdy_McGee

Howdy_McGee

    Programmer

  • Members
  • PipPipPipPip
  • 135 posts
:S wow im an idiot. Thanks !




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users