Forum Moderators: open

Message Too Old, No Replies

Help with innerHTML.replace

         

BlackRaven

2:50 pm on May 1, 2007 (gmt 0)

10+ Year Member



my innerhtml.replace doesn't seem to work?

function voting(postid)

{

$("voteid"+postid).innerHTML="Loading...";

new Ajax.Request("/voting.php", {method:"post", postBody:"postid="+postid});

new Ajax.Updater("voteid"+postid, "/voting.php");

$("voteid"+postid).innerHTML.replace("javascript:voting("+postid+")","");

}

<a href="javascript:voting(4)" id="voteid4">

whoisgregg

3:35 pm on May 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In Prototype [prototypejs.org] the replace method [prototypejs.org] refers to the innerHTML property of the element already -- you don't need to include it. This should work fine:

$("voteid"+postid).replace("javascript:voting("+postid+")","");

Although, I don't think it will accomplish what you want to accomplish. Post back if that's not what you expected.

BlackRaven

6:30 pm on May 1, 2007 (gmt 0)

10+ Year Member



i figured out the voted part however i need help with my total variable. I get the [object HTMLFontElement] instead of my total count.

function voting(postid)

{

$("voteid"+postid).innerHTML="Loading...";
new Ajax.Request("/voting.php", {method:"post", postBody:"postid="+postid});
new Ajax.Updater("voteid"+postid, "/voting.php");
$('voteid'+postid).replace('Voted','');
var total=$('total'+postid)+1;
$('total'+postid).innerHTML=total;

}

<font id="total4">1</font><a href="javascript:voting(4)" id="voteid4">Add Vote</a>

[edited by: BlackRaven at 6:33 pm (utc) on May 1, 2007]

whoisgregg

1:49 pm on May 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In that case, you are storing the total in the
.innerHTML
but not referencing that to get the total back out of it. The two forms need to match:

var total=$('total'+postid)[b].innerHTML[/b] +1; 
$('total'+postid)[b].innerHTML[/b]=total;

See what I mean? Now,

.innerHTML
is probably considered a string so you'll see concatenation instead of addition when you add that 1 and you probably would prefer "5" over "11111" right? :)

So just cast the

.innerHTML
as an integer before performing the addition:

var total= [b]parseInt([/b]$('total'+postid).innerHTML[b])[/b] +1; 
$('total'+postid).innerHTML=total;