Welcome to Discuss Everything Forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.


 

Tags for this Thread

+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Bill S's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Jun 2009
    Posts
    314
    Downloads
    0
    Uploads
    0

    How to put value of paragraph into JavaScript variable in an AJAX function.?

    Say I have a paragraph in a div:
    <div id="div1">
    <p id="para1">10</p>
    </div>
    now, I should be able to call in a JavaScript function:
    var ptext = document.getElementById('para1');
    var text = ptext.innerHTML;
    but it's not working and as a result my whole function stops. What am I doing wrong?

  2. #2
    Pratip's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Nov 2009
    Posts
    16
    Downloads
    0
    Uploads
    0
    Its working absolutely fine in my machine. Seems some other problems


  3. #3
    Pratip's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Nov 2009
    Posts
    16
    Downloads
    0
    Uploads
    0
    Its working absolutely fine in my machine. Seems some other problems


  4. #4
    Pratip's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Nov 2009
    Posts
    16
    Downloads
    0
    Uploads
    0
    Its working absolutely fine in my machine. Seems some other problems


  5. #5
    Itison's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Aug 2009
    Posts
    8
    Downloads
    0
    Uploads
    0
    It should work... in this case I think innerText should get you the same thing. What OS and browser are you using? Try getting a debugger, it'd be quite useful. I use Visual Studio but only because I'm also doing ASP.NET, and it handles JavaScript as well. But there are many other, more lightweight JS-specific debuggers out there.

  6. #6
    Steve's Avatar
    Senior Member

    Status
    Offline
    Join Date
    May 2009
    Posts
    1,329
    Downloads
    0
    Uploads
    0
    working example:

    <script language="javascript">
    function test(ID) {
    obj = document.getElementById(ID);
    var bloop = obj.innerHTML;
    alert(bloop);
    }
    </script>
    <a href="#" onclick="test('beans')">bloop</a>

    <div id="beans">300</div>

  7. #7
    thedoctorwho_42
    thedoctorwho_42's Avatar
    Guest
    Are you trying to do document.getElementById('para1'); before or after that paragraph is loaded? If its in the head and not in a domready event, it will tell you that ptext is null or something. Hope that helps.

 

 

Quick Reply Quick Reply

Click here to log in


What comes after M0nday

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 04-01-2010, 01:35 AM
  2. Replies: 0
    Last Post: 03-25-2010, 06:38 PM
  3. Replies: 1
    Last Post: 12-12-2009, 07:51 AM
  4. Replies: 0
    Last Post: 12-04-2009, 11:13 PM
  5. Replies: 0
    Last Post: 12-02-2009, 06:16 PM

Bookmarks

Posting Permissions

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