|
Ouch
Aug 16, 2010 13:23:14 GMT
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]
|
|
|
|
Ouch
Aug 16, 2010 15:14:56 GMT
Maybe i'm tired, but it looks like you just forgot a } at the end. =)
|
|
|
|
|
Ouch
Aug 16, 2010 19:56:41 GMT
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] + ")");
|
|
|
|
Ouch
Aug 16, 2010 20:13:23 GMT
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]
|
|
|
|
Ouch
Aug 16, 2010 20:19:46 GMT
Another silly oversight on my part.
i[x].onclick = new Function("return confirm('" + nopming[k][1] + "')");
|
|
|
|
Ouch
Aug 16, 2010 20:36:30 GMT
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]
|
|
|
|
Ouch
Aug 16, 2010 20:43:42 GMT
Looks fine to me. Just make sure you're targeting all the right pages.
|
|
|
|
|
Ouch
Aug 21, 2010 0:30:07 GMT
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.
|
|
|
|
|
Ouch
Aug 26, 2010 3:03:00 GMT
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]
|
|
|
|
Ouch
Aug 26, 2010 3:09:13 GMT
Nope.
|
|
|