Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Replace HTML Output Code


  • Please log in to reply

#1
hireconor

hireconor

    New Member

  • Member
  • Pip
  • 2 posts
This seems like it would be possible with JavaScript, but I can't find it anywhere! All I want is a function in the source code to find this fragmented code:

<tr> 
 <td> 
ADD Shoes

and replace with:

<tr><td>Extra Text</td><td>
 <tr> 
 <td> 
ADD Beef

How can I do this?

  • 0

Advertisements


#2
MS-Free

MS-Free

    Member

  • Member
  • PipPipPip
  • 425 posts
Actually it may be easier than you think. I believe something like this might work:

for (var i = 0; i < document.TableName.elements.length; i++) {
	 if (document.TableName.elements[i].innerHTML == "Shoes") { 
		 document.TableName.elements[i].innerHTML = "Beef";
		 document.TableName.elements[i].previousSibling.insertBefore("<tr><td>Extra Text</td><td>");
	 }
   }

Of course, that requires naming the table, like this:

<table name="TableName">


This is justhis ant a theoretical answer. I haven't actually tested it as its meant to give you a general idea, and perhaps not the exact answer.

W3Schools was extremely useful in constructing this solution. If this doesn't work, or even if it does, you may want to look at the resources they provide.
  • 0

#3
hireconor

hireconor

    New Member

  • Topic Starter
  • Member
  • Pip
  • 2 posts
Actually my example is confusing, I just want to...

add a table row above another table row that has ADD Beef as its text.

Is this correct and show I put it in the header tag or at the bottom of the page?
<script type="text/javascript"> 
   for (var i = 0; i < document.msgBox.elements.length; i++) {
	 if (document.TableName.elements[i].innerHTML == "<tr><td>ADD Beef") { 
		 document.TableName.elements[i].previousSibling.insertBefore("<tr><td>Additional Items</td><td>");
	 }
   }
</script>

  • 0

#4
MS-Free

MS-Free

    Member

  • Member
  • PipPipPip
  • 425 posts
IF it's correct, and I'm not sure whether it is, it presumably belongs in the HEAD, and even there I'm not sure, I'm not a JS expert.

If this is to be triggered by an action you'd have to make it a function, so it could be called when the said action is taken.

Basically:

function FunctionName () {
  ...
}

and than to trigger it something like this

<a onClick="FunctionName()">click to trigger</a>


Do you have any programming experience? That could be very helpful to you. Can you even follow the theory of my previously posted theoretical answer? Put differently - do you understand what each statement is supposed to be doing?

Also, you need to remain consistent. Understand that TableName could be anything, it could be laskdjgklsahdg for all anyone cares. However, you have to consistently refer to it as such.

I emphasis this because I noticed that in your permutation you used "msgBox", but continued to use "TableName" in both of the following occurrences.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP