#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2007
    Posts
    67
    Rep Power
    8

    Get text string from div


    i am trying to create a search indexer for my site. but i use php to include the menus and header on every page, so it automatically adds links from those to the index db. i am trying to use javascript to get all the text from a div i specify using id's. the following code gives me an error message:
    'd has no properties'
    Code:
    function getText(divname)
    {
      d=document.getElementById(divname);
      return d.value;
    }
    what can i do instead to get all the text from a div?
  2. #2
  3. :)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Oct 2006
    Location
    IL
    Posts
    1,520
    Rep Power
    441
    The value property only works if you are working with form fields. Use innerHTML instead. It would be return d.innerHTML;
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2007
    Posts
    67
    Rep Power
    8
    Originally Posted by huyaroo
    The value property only works if you are working with form fields. Use innerHTML instead. It would be return d.innerHTML;
    i am using firefox 2 and have tried what you said.
    i just get an document.getElementById(divname) has no properties.
    Code:
    function getText(divname)
    {
    	var html = document.getElementById(divname).innerHtml;
    	return html;
    }
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2007
    Posts
    67
    Rep Power
    8
    Originally Posted by alicats12345
    i am using firefox 2 and have tried what you said.
    i just get an document.getElementById(divname) has no properties.
    Code:
    function getText(divname)
    {
    	var html = document.getElementById(divname).innerHtml;
    	return html;
    }
    i have sorted this out. i had a syntax problem

IMN logo majestic logo threadwatch logo seochat tools logo