0

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>

1
  • Why are you doing one of those echoes server-side and one client-side? Why not just echo "username good" in the same place that you're echoing "available"? Commented Nov 14, 2014 at 3:59

2 Answers 2

1

A div doesn't have a value property, you need to use innerHTML:

var username_good = document.getElementById('feedback').innerHTML;
Sign up to request clarification or add additional context in comments.

Comments

0

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

    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.