开发者

Javascript alert php result

First of all sorry im a really big beginner

I have a bit开发者_StackOverflow of a problem

i have a mysql query what select data from my users

the code looks like this

$r = mysql_query(" SELECT reader FROM users WHERE username = 'Tom' ") or die (mysql_error());
$result = mysql_fetch_array($r);

$vv = $result['reader'];

echo '<div id="reader">'.$vv.'</div>';

so it selects tom is a reader, the reader field contains yes or no, i echo it out it says yes, thats ok.

and i would like to alert this value with javascript.

i added an id reader

the javascript

<script>
var readers = document.getElementById("reader"); 
        alert(readers.value);



</script>

and im keep getting an alert window undefined.

could please someone point me to te right path what im missing? and is it possible to alert the value this way?


element.value will try to read the "value" attribute for the element. Use innerHTML and you will get the elements including text inside of the element <el>this is the inner html</el> in a string:

alert(readers.innerHTML);


.value will look for the value="" attribute of an element and therefore will throw back undefined if this attribute is not applied to the element in question.

So you don't want .value you want .innerHTML


Try this in jquery

<script>
      alert($("#readers").html());    
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜