I have a field in my weblog where a price can be entered on my site which is run with EE 1.7.1. In the template, I have a javascript code that adds a comma and a dollar sign. The problem is that in the latest weblog entries, it is sending the entry field to the template wrapped in paragraph tags. The tags don't show up when I look at the weblog itself, but when I inspect where it should be on the page, the source code shows the tags.
I have tried adding script to remove the tags, but it seems like the html tag is crashing the code.
My code, both for removing the tags and for adding the comma and dollar sign is
function checkP(p){
if(p.substring(0,3) == "<p>")
p = p.substring(3,s.length-4);
return p;
}
function stripTags(p){
var StrippedString = p.replace(/(<([^>]+)>)/ig,"");
return StrippedString;
}
function addComma(amount){
if(typeof amount == "string"){
var a = checkP(amount);
}else{
var a = amount.toString();
}
if(a.length > 3){
var x = a.substring(0,a.length-3);
var y = a.substring(a.length-3, a.length);
var b = x + "," + y;
document.write(b);
}else{
document.write(a);
}
}
My code that is controlling the price is
<div id="inv_price">
{if cf_inv_msrp!=""}MSRP: <b>$<script>addComma(stripTags({cf_inv_msrp}));</script></b>
{if:elseif cf_inv_price !="" AND cf_inv_price!="0"}Price: <b>$<script>addComma({cf_inv_price});</script></b>
{if:else}<b>Call for Price</b>{/if}
</div>
When I add an alert to addComma, it never gets called which leaves me to believe that the tags are messing up the script's call.
The code works for all of the other entries, and I've tried removing the price and added it again. For an example of what the script should output, you can look at this site.