#00AF33
14306
0
1
Sept 8, 2023 8:54:17 GMT -8
Jordan
What is truth?
11,838
October 2003
jab2
|
Post by Jordan on Aug 31, 2011 7:58:42 GMT -8
Another quick question. I have not seen a tutorial on this, but I know it is possible, because I have seen it done several times. I guess it would be considered an array. The type of array that i am talking about is the type that lets the code user specify multiple values to a variable. Say they needed to specify certain usernames in the code; Let's pretend that the code only let the specified usernames post. For example var mayPost = "username1, username2, username3, etc" if(pb_username == mayPost)I have been reading up on this and have came up with; var mayPost = ["username1","username2","username3"]and var mayPost = new Array("username1","username2","username3")and referenced both of the metods above using if(pb_username == mayPost)But none have worked. What am I doing wrong here? If you wanted to use the == operator, you would have to do it for each string in the array. However, that would require a lot of typing if you did it in one big if statement. You could loop through the array using a loop, but there's a better way and that's using a regular expression. var staff = /^(admin|user1|user2|user3)$/i; if(staff.test(pb_username)) { // One of the names matched }You could also use the .match() function like you have been using, but it returns an array of all the matched elements which you probably don't need in this scenario so it's faster to call test. If you did use the match function it would look like this. var staff = /^(admin|user1|user2|user3)$/i; if(pb_username.match(staff)) { // One of the names matched }I explained the regular expression part earlier, but just to quickly go over it again: ^ means we must start matching at the beginning of the string, and $ means the match must continue to the end of the string. The syntax (one|two|three) means we can match one of those items. If we didn't have the ^ and someone's username was "fakeadmin", "admin" would match because we aren't concerned with how the string starts.
|
|
Former Member
inherit
guest@proboards.com
155913
0
Nov 23, 2024 7:53:51 GMT -8
Former Member
0
January 1970
Former Member
|
Post by Former Member on Aug 31, 2011 8:41:43 GMT -8
Got ya. Very much appreciated!
|
|
#00AF33
14306
0
1
Sept 8, 2023 8:54:17 GMT -8
Jordan
What is truth?
11,838
October 2003
jab2
|
Post by Jordan on Aug 31, 2011 8:53:00 GMT -8
No problem, let me know if got any more questions.
|
|
Former Member
inherit
guest@proboards.com
155913
0
Nov 23, 2024 7:53:51 GMT -8
Former Member
0
January 1970
Former Member
|
Post by Former Member on Sept 3, 2011 13:12:42 GMT -8
OK, I have come across another situation that I can't bare to figure. I am trying to match a string and replace it.
The string is "in"
lastPost = document.getElementById("LP") lastPost.innerHTML = lastPost.innerHTML.replace("in", ", in")
The problem is that there are many occurrences of "in". The code even digs deep into the elements innerHTML and replaces any occurrence of "in", even in the links that are in the element.
For example, it will change the word "index" in the url to "in, dex" or "admin" to "adm, in"
I just want it to replace the word "in" And this has been tricky to me because "index" starts with "in", and admin ends with "in". So I have tried using many of replace() properties such as \b, ^, $, g, i, and many others.
But the code I am building may easily have more occurrences of "in" than just "index" and "admin"
How do I target one specific word at a specific location?
What would solve the problem even simpler is if there is a "standard" way of replacing <br/> with a whitespace.
|
|
#00AF33
14306
0
1
Sept 8, 2023 8:54:17 GMT -8
Jordan
What is truth?
11,838
October 2003
jab2
|
Post by Jordan on Sept 3, 2011 13:32:10 GMT -8
Try checking for spaces (\s) on both sides. You'll also want to add the /g modifier (global) so you replace all instances of the pattern.
lastPost.innerHTML = lastPost.innerHTML.replace(/\sin\s/gi, ", in ");
lastPost.innerHTML = lastPost.innerHTML.replace(/<br\s?\/?>/gi, "");
"\s?" means it will match a whitespace if one exists, but it doesn't have to exist. "\/?" means the same thing, but with the "/". We have to add these checks because XHTML requires the line break be typed like: <br />, but not everyone types them like that on Proboards so this will also match <br/> and <br>.
|
|
Former Member
inherit
guest@proboards.com
155913
0
Nov 23, 2024 7:53:51 GMT -8
Former Member
0
January 1970
Former Member
|
Post by Former Member on Sept 3, 2011 14:21:35 GMT -8
Cool deaL! There was a space after "in", which made it unique in this situation. I used
lastPost.innerHTML = lastPost.innerHTML.replace(/in\s/gi, ", in ")
Thanks again for your help Jordan! I would be stuck even more than I am already if I couldn't refer back to here with my questions. But I try to make you last resort so that i'm not bugging the hell out of ya. For instance, I spent a good 3 or 4 hours trying to find a solution for this particular situation before I asked you.
|
|
#00AF33
14306
0
1
Sept 8, 2023 8:54:17 GMT -8
Jordan
What is truth?
11,838
October 2003
jab2
|
Post by Jordan on Sept 4, 2011 20:53:30 GMT -8
No problem, I don't mind at all. Ask all the questions you would like.
|
|
Former Member
inherit
guest@proboards.com
155913
0
Nov 23, 2024 7:53:51 GMT -8
Former Member
0
January 1970
Former Member
|
Post by Former Member on Sept 5, 2011 7:40:58 GMT -8
OK, here I go again ........ I am writing a code, and I am attempting to make one of it's features alert the user on the homepage when a topic that they have participated in has been replied to. I have tried this using the following method: If on the (boardindex) page, the browser finds this ( ) image, it then alerts back to the home page "Your Topics have new post". It's going to be within a code before it is all over, so it wont actually be an annoying typical pop up.I am just using the alert (at the moment) basically for a crash dummy until I figure this method out.Of course, I have easily accomplished "the alert" on the (boardindex) page, if the "new" image is found, but I can't figure out how to accomplish "the alert" on the (Home) Page, if the image is found on the (boardindex) page. So basically, in a nut shell.. when the browser opens the website, it checks to see if the "new" image is on the (boardindex) page. If the condition is true, it then activates the alert.
|
|
#00AF33
14306
0
1
Sept 8, 2023 8:54:17 GMT -8
Jordan
What is truth?
11,838
October 2003
jab2
|
Post by Jordan on Sept 5, 2011 10:53:07 GMT -8
If on the (boardindex) page, the browser finds this ( ) image, it then alerts back to the home page "Your Topics have new post". Since Javascript only exists and is executed on the client side, this isn't really possible unless you open up an iframe or make an ajax call to the boardindex page. Unfortunately, using those methods is against the TOS because the user doesn't get a chance to see or click the ads and it also adds strain to the Proboard servers (there would basically be double the requests for everyone on the home page of the forum which can add up quickly if the code is being used by a lot of forums). So basically, in a nut shell.. when the browser opens the website, it checks to see if the "new" image is on the (boardindex) page. If the condition is true, it then activates the alert. Yeah, this just isn't possible on Proboards without access to some sort of API or the ability to make ajax calls or open iframes.
|
|
Former Member
inherit
guest@proboards.com
155913
0
Nov 23, 2024 7:53:51 GMT -8
Former Member
0
January 1970
Former Member
|
Post by Former Member on Sept 5, 2011 11:24:10 GMT -8
I figured that.
I was on the right trail though. I was looking in to Ajax, cookies, and iframes.
I better take a read at TOS rules ;D
So basically, we are limited to creating our codes only using the information and data that is used on that particular page?
understandable .... but still leaves me confused. Like, how did Wormo make his last topics relocate code?
I skimmed through that, but couldn't really pick it apart.
But isn't it true that the code retrieves info from the "New Topics" page? Or from somewhere that is not the home page?
Well, I'll re-think my code. Thanks like always!
|
|
inherit
97216
0
Nov 15, 2024 16:10:17 GMT -8
Bennett 🚀
Formerly iPokemon.
3,622
January 2007
catattack
iPokemon's Mini-Profile
|
Post by Bennett 🚀 on Sept 5, 2011 18:35:23 GMT -8
If you had the previous posts box instead of the leaderboard ad, you could check for new post icons there, and just hide the table and keep the ad there.
|
|
#00AF33
14306
0
1
Sept 8, 2023 8:54:17 GMT -8
Jordan
What is truth?
11,838
October 2003
jab2
|
Post by Jordan on Sept 6, 2011 8:13:11 GMT -8
So basically, we are limited to creating our codes only using the information and data that is used on that particular page? Yes. You can set cookies or use the localStorage object to store persistent data, but the user has to visit the page first. understandable .... but still leaves me confused. Like, how did Wormo make his last topics relocate code? I skimmed through that, but couldn't really pick it apart. He only grabbed the last post of each board from the "Last Post" column on the main page.
|
|
Former Member
inherit
guest@proboards.com
155913
0
Nov 23, 2024 7:53:51 GMT -8
Former Member
0
January 1970
Former Member
|
Post by Former Member on Sept 6, 2011 8:42:23 GMT -8
If you had the previous posts box instead of the leaderboard ad, you could check for new post icons there, and just hide the table and keep the ad there. Yes, I was trying to figure a way to grab that even if it wasn't being used by the admin of the site. Yet, now that ya mention it, I could make having the last post box one of the requirements to use the code, and maybe just hide it like ya say and build a new welcome table in place of the previous post box within the code so that the user is still pleased. Hmmm, interesting. EDITohh yea, the ad will still be a problem........ ..like you already mentioned
|
|
Former Member
inherit
guest@proboards.com
155913
0
Nov 23, 2024 7:53:51 GMT -8
Former Member
0
January 1970
Former Member
|
Post by Former Member on Sept 6, 2011 8:43:49 GMT -8
So basically, we are limited to creating our codes only using the information and data that is used on that particular page? Yes. You can set cookies or use the localStorage object to store persistent data, but the user has to visit the page first. understandable .... but still leaves me confused. Like, how did Wormo make his last topics relocate code? I skimmed through that, but couldn't really pick it apart. He only grabbed the last post of each board from the "Last Post" column on the main page. ok, ok, I see what he did now. Like always, thanks alot Jordan!
|
|
Former Member
inherit
guest@proboards.com
155913
0
Nov 23, 2024 7:53:51 GMT -8
Former Member
0
January 1970
Former Member
|
Post by Former Member on Jul 15, 2012 21:49:20 GMT -8
Hello again. It's been a while. I'm back for some answers. Recently I have started creating a new code. It is a Profile Remodel code. I have completely stripped the original Profile page of all tables and started fresh with the page remodel. I have also created a form that allows the user to change varioius properties of their personal profile, such as the body background, their profile pic, the color of certain tables and things of that nature. The form works great. Everything works fine with the click of one button. (That button being the submit buttton to submit the form) THE PROBLEM: is that when the Profile page is left and then reloaded, all of the changes that were made due to the form submission are lost and not saved. MY QUESTION: is how to get the form submission to save? How to make the changes that the user makes to their profile be saved so that the page saves the changes after it has been left and reloaded. ??
|
|