Reputation: 35
I have a php page the verifies the username users type in, and echo's back "available!" if its available into a div called "feedback". now I have this JavaScript that I want to check to see if the "feedback" div says "available! and echo "username good" into the "check" div if it is. but it doesn't work and i don't know why.
<script type='text/javascript'>
function check_info(){
var username_good = document.getElementById('feedback').value;
if(username_good == "available!"){
document.getElementById("check").innerHTML = "username good";
}
else{
document.getElementById("check").innerHTML = "bad";
}
}
</script>
Upvotes: 0
Views: 119
Reputation: 9508
Fiddle for the same added.
<div id="feedback">test</div>
<div id="check"></div>
<input type="button" onclick="javascript:check_info()" value="Validate">
function check_info(){
var username_good = document.getElementById('feedback').innerHTML;
if(username_good !== ""){
document.getElementById("check").innerHTML = "username good";
}
else{
document.getElementById("check").innerHTML = "bad";
}
}
Upvotes: 0
Reputation: 5742
A div doesn't have a value
property, you need to use innerHTML
:
var username_good = document.getElementById('feedback').innerHTML;
Upvotes: 1