SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2005
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with replace text script

    I can't get the script to work that will replace old text with new text in specified th:

    html content:
    Code:
    <table align="center" cellspacing="1" class="homepagemodule report" id="trade_bait">
    	<caption>
    		<span>Trade Bait</span>
    	</caption>
    	<tbody>
    	<tr>
    		<th class="franchisename">Franchise</th>
    		<th class="willgiveup">Will Give Up</th>
    		<th class="inexchangefor">In Exchange For</th>
    		<th>Trade?</th>
    	</tr>
    I would like to replace "Will Give Up" in second th with "Offered" and here's script I did that didn't worked:

    Code:
    function replaceText () {
    	var offeredparent = document.getElementById('trade_bait').getElementsByTagName("tbody")[0].getElementsByTagName('tr').getElementsByTagName('th')[1];
    	var str = offeredparent.textNode.nodeValue;
    	tr = str.replace('Will Give Up','Offered');
    	offeredparent.textNode.nodeValue = str;
    }
    Could use help to correct this or suggest different script that would work better.

    appreciate the help!

    jace

  2. #2
    SitePoint Member
    Join Date
    Dec 2004
    Location
    New Philadelphia
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just out of curiousity, what is this line doing?


    Code JavaScript:
    tr = str.replace('Will Give Up','Offered');

    Is tr referencing something else in the global scope?

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2005
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Opps, it's copy/paste typo, here's correct one:

    Code:
    function replaceText () {
    	var offeredparent = document.getElementById('trade_bait').getElementsByTagName("tbody")[0].getElementsByTagName('tr').getElementsByTagName('th')[1];
    	var str = offeredparent.textNode.nodeValue;
    	str = str.replace('Will Give Up','Offered');
    	offeredparent.textNode.nodeValue = str;
    }


Bookmarks

Posting Permissions

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