Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace Text 2

Status
Not open for further replies.

jloffredo

Technical User
Joined
Feb 24, 2002
Messages
17
Location
US
I use a shopping cart for my online storefront. The cart automatically displays the weight of each item, for example "Weight: 3.00 lbs. each". Does anyone have sample code that would search for and remove any string starting with "Weight" and ending with "each"?

Thanks in advance...John
 
string.replace(/Weight.*Each/,"")

--Chessbot

The program didn't do anything wrong; it did exactly what you told it to!
 
string.replace(/^Weight.*Each$/ig,"")

Known is handfull, Unknown is worldfull
 
Thanks for the help. Now what do I do with this. I put it in the Body of the html and nothing happened. Is there other syntax that needs to go around it?

Sorry for the newbie qustion.

John
 
Code:
<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
<!-- hide from old browsers

function removeWeights()
{
  var myform = window.document.myform; // change to your form's name
  var mytext = myform.tbox // change to your textbox's name
  mytext.value = mytext.value.replace(/^Weight.*Each$/ig,"") 
}
// end hide -->
</script>
</head>
<body>
<form name="myform" onSubmit="removeWeights();">
<textbox name="tbox">
</textbox>
</form>
</body>
</html>


--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 
Thanks, but I don't think I accurately described my need. Below is a sample of the basket from my cart. The weight is dynamically generated by the cart. I'm looking to have the code automatically loop through the page upon loading and remove all the lines that give the weight.

John





Qty Description Unit Amount Remove

--------------------------------------------------------------------------------

6 Pack Seamless Bow Lace Dress With Key Hole Front $60.00 $120.00
Weight: 3.00 lbs. each
Color is White

--------------------------------------------------------------------------------

6 Pack Checker Opaque Bodystocking $27.00 $27.00
Weight: 3.00 lbs. each
Color is Black/White

--------------------------------------------------------------------------------

 
OK then...
Code:
<script type="text/javascript">
function removeWeights()
{	document.body.innerHTML = document.body.innerHTML.replace(/Weight.*Each/ig,"");
}
</script>
If you have access to any tag that contains HTML you want to change, use it instead of document.body.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top