Topeka
Junior Member
Posts: 94
Topeka said 0 great things
|
Post by Topeka on Apr 17, 2010 11:56:08 GMT -8
How can i check to see if something has a value?
like for example if i find Posts: in the miniprofile (only the number), and i make it =postnum so something like this
assuming string is the MP post found.
string="Posts: 967" postnum=string.split('Posts: ')[1];
then make a document.write("You've made "+postnum+" posts") somewhere. how can i check to make sure postnum has a value? like
if (postnum==[[[somthing here???]]]) { document.write("You've made"+postnum+"posts") }
and i was also going to do this to text. like Location, so the value will not always be a number value if there.
|
|
|
Post by Wormopolis on Apr 17, 2010 12:29:42 GMT -8
if you look at the HTML for the MP, you will notice that there is a <br> tag immediately following the post count. so you could effectively split the innerHTML of the mp cell
postcount=mpcell.split('posts:')[1].split(/<br>/i)[0];
if you want to use it as a number, remove the commas and recast it as an int:
postcount=parseInt(postcount.replace(/,/g,''));
|
|
Topeka
Junior Member
Posts: 94
Topeka said 0 great things
|
Post by Topeka on Apr 17, 2010 13:46:27 GMT -8
Uh. yes...?
i already have the post number. i did it by splitting the entire mp cell from <br>'s i saw it done before, so i tried it out.
i got this for finding the posts
miniArray=tds.innerHTML.split(/<br>/i); for (e=0; e<miniArray.length; e++) { if (miniArray[e].match(/posts:/i) && posts=='') { posts=miniArray[e].split('Posts: ')[1]; } }
So i have the post number already. but im asking for a way to make sure they have a value there, like for location, if they dont have one, it doesnt show in the mp. But when i type in
document.write("You've made"+postnum+"posts") and theres no value for postnum. then it displays "You've made posts"
But i wanna make it if there is no value for postnum. then that entire sentence is gone.
so ill need to make it in an if statement making the sentece if postnum has a value. which i dont know how to check.
might not of been the best example cause you'll always have a post number there whether its 0 or not. but do you get what im looking at?
(and actually i'll ask this later, but i kept getting undefined for it for awhile when finding the different name,rank,location,joined,posts,etc. then i looked around and i saw one of your codes actually, and you had the exact same thing only with && posts=='' or && gender==" with a post=gender=location=name='' at the top. so i added them and it worked. But, i have no idea why it was done, and why it made it work. but ill ask that later.)
|
|
|
Post by Wormopolis on Apr 17, 2010 18:05:28 GMT -8
heh heh.. I started out with a headache when I read that post and it got worse...
use the tertiary operator inside the document.write
document.write(postcount != '' ? "You have made "+postcount+" posts" : "You made some posts");
I'll answer your other question later.
|
|
Topeka
Junior Member
Posts: 94
Topeka said 0 great things
|
Post by Topeka on Apr 18, 2010 13:50:18 GMT -8
lol sorry. im not that great at explaining my questions. lol
i did that, and im getting a undefined right now. but im busy right now. so i gota find out whats doing that later..
|
|
|
Post by Wormopolis on Apr 18, 2010 14:45:46 GMT -8
you could check to make sure postcount has what you are expecting it to have by doing an alert(postcount) above the document.write line
|
|
Topeka
Junior Member
Posts: 94
Topeka said 0 great things
|
Post by Topeka on Apr 21, 2010 11:23:42 GMT -8
i had to change around a few things. so i now have a bunch (15+) of Nwrw.cells[0].innerHTML=Nwrw.cells[0].innerHTML.replace(/_name/g,name); instead of document.write() lol would i still do the same thing when writing this? Nwrw.cells[0].innerHTML=Nwrw.cells[0].innerHTML.replace(/_name/g,name !='' ? "Your name is"+name : "You have no name"); Edit: im going to have to say yes to my own question, i tried it real quick and i got it to work idk why i was getting a undefined before. but it seems to work right now. i think it had to do with where and how i was placing it there.
|
|
|
Post by Wormopolis on Apr 23, 2010 3:58:09 GMT -8
so everything good then?
|
|
Topeka
Junior Member
Posts: 94
Topeka said 0 great things
|
Post by Topeka on Apr 23, 2010 13:39:23 GMT -8
unless you want to explain why you need to have the green part of the below lines in finding the elements in a miniprofile.
i tried this <br> split method, and after fiddling for awhile it still didnt work. couldnt figure out why. so i saw one of your mp edits. and i noticed you basicly followed the same thing except you had what you have in green now. and i cant figure out why you do. my only guess is to try to sign the variables outside the
miniArray=tds[i].innerHTML.split(/<br>/i); for (e=0; e<miniArray.length; e++) {} But its just a guess.
Other than this I'm great everything has been working the way i've hoped. So thank you on showing me the operator.
|
|
|
Post by Wormopolis on Apr 23, 2010 13:46:16 GMT -8
I did that so it wouldnt pick up a second match of something.
lets say someone was being cute and put their location as
Posts: 1,000,000
the method I used would have already picked up a postcount and ignored the second time it found it.
|
|
|
Post by Wormopolis on Apr 23, 2010 13:48:07 GMT -8
p.s. did you notice what happens when you hover over someone's name?
|
|
Topeka
Junior Member
Posts: 94
Topeka said 0 great things
|
Post by Topeka on Apr 23, 2010 17:10:18 GMT -8
I did that so it wouldnt pick up a second match of something. lets say someone was being cute and put their location as Posts: 1,000,000 the method I used would have already picked up a postcount and ignored the second time it found it. Ok, it makes sence, but why would it not work without it then? The values came out as undefined until i did that, and then it worked great. so do you know why doesnt it work w/o it? And yup, i did notice the 'Last 10 posts' box.
|
|
|
Post by Wormopolis on Apr 23, 2010 18:32:14 GMT -8
it also servs the purpose of declaring those variables in the same scope as the level I ended up using them. if you declare inside the if statement, then the scope stays at THAT level.
|
|
Topeka
Junior Member
Posts: 94
Topeka said 0 great things
|
Post by Topeka on Apr 24, 2010 9:54:03 GMT -8
ah ok ok. Thanks
|
|