Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to get Div values

    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

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,309
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    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

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,613
    Thanks
    80
    Thanked 4,635 Times in 4,597 Posts
    But if you are going to do *THIS*:
    Code:
    <div id="search_suggest" onmousedown="item_list(this))"></div>
    Then you don't need to use getElementById in your function, at all.

    Just use:
    Code:
    function item_list(div)
    {
        var xmlhttp;
        var str = div.innerHTML;
    
        alert(str);
        ... rest same ...
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •