Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

Joe Kerr

Joe Kerr Avatar
Why So Serious?



769


June 2010
Ok i am really dumb when it comes to coding. I am trying to learn what to do in certain situations. I figured out how to do arrays not that long ago but i don't know how to do the same thing with a var. This is my fail at trying...

<script type="text/javascript">
// Alert before PMing

var nopming=[
["admin", "Please do not message the admin for support"],
["nightwalker", "Please do not PM me for anything having to do with support"] //No comma on last line
];

if(/^(search2|display|viewprofile)$/.test(pb_action)) {
var i = document.links;
for(k=0;k<nopming.length;k++){
for(var x = 0; x < i.length; x ++){
if(i[x].href.indexOf("action=pmsend&to=" + nopming[k][0]) > -1)
i[x].onclick = function() { return confirm(""+ nopming[k][1]) }
}
}
}
</script>

Anyone care to tell me what i did wrong? I know it is bad but i don't quite understand the var thing yet. I looked at w3schooles and couldn't find it either so...


Last Edit: Aug 16, 2010 19:26:05 GMT by Joe Kerr
Building Your Proboard, a Basic Guide to Getting Your Forum Started



Need somewhere to host files?[/url]

Aaron

Aaron Avatar
Bad Wolf

****
Dedicated Studio Member

859


November 2006
Maybe i'm tired, but it looks like you just forgot a } at the end. =)

Joe Kerr

Joe Kerr Avatar
Why So Serious?



769


June 2010
still not working...
Building Your Proboard, a Basic Guide to Getting Your Forum Started



Need somewhere to host files?[/url]

Aaron

Aaron Avatar
Bad Wolf

****
Dedicated Studio Member

859


November 2006
Your onclick function grabs nopming[k][1] each time the user clicks a link. This is after your loop has run and k is at 2. So no matter what user they pm to, they'll get confirm("" + nopming[2][1]). The error comes from trying to access an element of an undefined value.

Easy fix:

i[x].onclick = new Function("return confirm(" + nopming[k][1] + ")");

Joe Kerr

Joe Kerr Avatar
Why So Serious?



769


June 2010
do i have that problem on the first one too? Because still it is not working

<script type="text/javascript">
// Alert before PMing

var nopming=[
["admin", "Please do not message the admin for support"],
["nightwalker", "Please do not PM me for anything having to do with support"] //No comma on last line
];

if(/^(search2|display|viewprofile)$/.test(pb_action)) {
var i = document.links;
for(k=0;k<nopming.length;k++){
for(var x = 0; x < i.length; x ++){
if(i[x].href.indexOf("action=pmsend&to=" + nopming[k][0] ) > -1)
i[x].onclick = new Function("return confirm(" + nopming[k][1] + ")");
}
}
}
</script>
Building Your Proboard, a Basic Guide to Getting Your Forum Started



Need somewhere to host files?[/url]

Aaron

Aaron Avatar
Bad Wolf

****
Dedicated Studio Member

859


November 2006
Another silly oversight on my part.

i[x].onclick = new Function("return confirm('" + nopming[k][1] + "')");

Joe Kerr

Joe Kerr Avatar
Why So Serious?



769


June 2010
Thanks...anything else i should add before submitting it? Or should i submit it?

<script type="text/javascript">
/* Alert before PMing by Nightwalker
Please do not edit without permission
for support go to joemaggio.proboards.com */

if(/^(search2|display|viewprofile|members)$/.test(pb_action)) {

// Edit Here
var nopming=[
["admin", "Please do not message the admin for support"],
["username", "message"],
["username", "message"] //No comma on last line
];
// No More Editing
var i = document.links;
for(k=0;k<nopming.length;k++){
for(var x = 0; x < i.length; x ++){
if(i[x].href.indexOf("action=pmsend&to=" + nopming[k][0] ) > -1)
i[x].onclick = new Function("return confirm('" + nopming[k][1] + "')");
}
}
}
</script>

I am going to put it in the Nightcode index but will other people accept the code?
Building Your Proboard, a Basic Guide to Getting Your Forum Started



Need somewhere to host files?[/url]

Aaron

Aaron Avatar
Bad Wolf

****
Dedicated Studio Member

859


November 2006
Looks fine to me. Just make sure you're targeting all the right pages.

Joe Kerr

Joe Kerr Avatar
Why So Serious?



769


June 2010
the only hole i can think of is if they have a link to PMing one of the members on the main page...or if they type it into the url bar...but i can think of a fix for that when someone needs it...
Building Your Proboard, a Basic Guide to Getting Your Forum Started



Need somewhere to host files?[/url]

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
Joe Kerr Avatar
the only hole i can think of is if they have a link to PMing one of the members on the main page...or if they type it into the url bar...but i can think of a fix for that when someone needs it...


One solution might be to actually do the alert on the PM page based on the URL. Your choice. :)

Joe Kerr

Joe Kerr Avatar
Why So Serious?



769


June 2010
Chris Avatar
Joe Kerr Avatar
the only hole i can think of is if they have a link to PMing one of the members on the main page...or if they type it into the url bar...but i can think of a fix for that when someone needs it...


One solution might be to actually do the alert on the PM page based on the URL. Your choice. :)


I was hoping to have the popup show BEFORE you got to the PM page so if you clicked cancel nothing would happen. If you did it by url would you be able to do that?
Building Your Proboard, a Basic Guide to Getting Your Forum Started



Need somewhere to host files?[/url]

Aaron

Aaron Avatar
Bad Wolf

****
Dedicated Studio Member

859


November 2006
Nope.

newBookmarkLockedFalling