...

View Full Version : how to get Div values



khalidhabib.cs
07-17-2012, 07:49 AM
Hello Friends
plz help me
there is a div
which contain a list of values I want get These values in a variable
bcz in that div I m using function which take perameter


function item_list(str){
var xmlhttp;
var str2=document.getElementById('search_suggest').value;

var str=document.getElementById('search_suggest').innerHTML=str2;

alert(str);
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("itemList").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","itemList.php?q="+str,true);
xmlhttp.send();

}

<div id="search_suggest" onmousedown="item_list(this))">
</div>
plz plz help

Philip M
07-17-2012, 08:08 AM
var str2=document.getElementById('search_suggest').value;

Should be

var str2=document.getElementById('search_suggest').innerHTML;


It is your responsibility to die() if necessary….. - PHP Manual

Old Pedant
07-17-2012, 11:54 PM
But if you are going to do *THIS*:


<div id="search_suggest" onmousedown="item_list(this))"></div>

Then you don't need to use getElementById in your function, at all.

Just use:


function item_list(div)
{
var xmlhttp;
var str = div.innerHTML;

alert(str);
... rest same ...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum