Click to See Complete Forum and Search --> : If statement confusion


FarFlungFish
05-09-2004, 12:48 AM
Hello again peeps,

i have already looked through some threads, but considering i don't even know the name of what im looking for i didn't come to much conclusion.
This is probably a walk in the park to most of you so ill make it as quick as i can.

I am writing a script for my site to display a default section if two query strings are empty; the other query strings are used to reference to sections etc.. I am doing this in ASP(sorry!!;)) JavaScript.

<% If (String(Request.QueryString("Section") == "" || String(Request.QueryString("Section")=="undefined"){//open%>
<% If (String(Request.QueryString("Additional")=="" || String(Request.QueryString("Additional")=="undefined"){//open%>
<html>(HTML CONTENT FOR NO CONTENT)</html>
<%}//close%>
<%}//close%>

What I think this does :

Basically, this script checks to see if the QueryStrings: Section and Additional have anything in them. If they do not; then the script will write the html for the "no content" section. Will this work at all (im new to this), and is there another way of doing this?

Any help would be much appreciated!! thanks

David Harrison
05-09-2004, 07:05 AM
I'm not sure why you need String( so I got rid of it, you hadn't closed your brackets for them anyway.


<% If ((Request.QueryString("Section") == "" || Request.QueryString("Section")=="undefined") && (Request.QueryString("Additional")=="" || Request.QueryString("Additional")=="undefined")){//open%>
<html>(HTML CONTENT FOR NO CONTENT)</html>
<%}//close%>
This should have been posted in the ASP forum, I'd move it but I don't have the power to moderate in this forum.

FarFlungFish
05-09-2004, 09:34 AM
Thanks,

i forgot to close them! argh. I was just using them for comedy value i suppose.. can't remember :)

Ill try it out and see what i get.

I was just having problems with multiple conditions from 2 different sources, if that makes sense:

If ((QueryString1)==0 || (QueryString1)==Undef) &&
((Querystring2)==0 || (QueryString2)==Undef){blah blah}

Hopefully that should have solved it though, thanks.

I don't see why it should be in asp, its just the same but server side. Its still JS not VB or anything.

But thanks V much for the reply anyhow!

David Harrison
05-09-2004, 09:44 AM
I hope it works for you.

This thread should have gone into the ASP forum because it is ASP. When you posted in here you run the risk of confusing members who don't know what the <% %> are.

Wouldn't it be easier to just check the length of the things in the querystring? Here's a little bit of VBScript that I use on one of my pages:
if Len(request.form("name"))>0 AND Len(request.form("comments"))>0 then

blah

end if
.form .querystring, same diff.

FarFlungFish
05-09-2004, 09:56 AM
Suppose the <%'s would be quite confusing to someone who has never used asp, good point.

Good idea with checking the string length, though i don't think i need the len method in javascript do i?

I take it you also use a script to display a section on one page dependant on which string is active, or has a value in it?

Thanks

David Harrison
05-09-2004, 10:52 AM
Originally posted by FarFlungFish
Good idea with checking the string length, though i don't think i need the len method in javascript do i?I've only every used VBScript for ASP so I don't on that one.

I'm using that code I posted on the process page of a guestbook (http://www11.brinkster.com/hackus/gb/gb.asp). It's just to make sure that all fields are filled in properly.
There is also an else to go with the if and that displays a form with the invalid fields highlighted with red labels.

FarFlungFish
05-09-2004, 10:56 AM
clever!


----
Well i have come up with this for getting the length of the querystring and checking it actually has something in it:


(String(Request.QueryString("Section")).length > 0)


This is because the Request.QueryString, does not support the .length... goodness knows i just hope it works. Im sure there is an easier way to do what im doing!

Thanks

David Harrison
05-09-2004, 11:00 AM
Originally posted by FarFlungFish
Request.QueryString, does not support the .lengthIt doesn't??? :eek:

Better switch to VB then. ;)

So what is this code being used for in yours?

FarFlungFish
05-09-2004, 11:09 AM
well i used to use vb for a while, but i find javascript more friendly... just not logical!! hehe

--
i use the code for a single page to display or hide different sections dependant on which section is selected... er hard to explain really.

Its just to have everything on one singular page, which reads from a database.. all the content is stored on the database; even picture urls, basic html for layout of articles etc. All is styled with css. Since all content is stored on a database, and what ever content may be pulled out will be displayed on on the same page, it means that i don't need to worry about keeping it consistent in style.
I know there are other ways of doing it; but im just doing this because it is my preference :)

Hope this makes sense!

--

Now that i got the querystring sorted out i can't figure out how to logic it correctly.. i want the string to work out if the string has anything there at all.. in either strings, though this just checks the length.. what if there was no string value? how do you think i could do that? dont worry bout language..

David Harrison
05-09-2004, 11:13 AM
If there's no string value then the length will be 0, since you're checking to see if the length>0 then your if/else will work fine.

FarFlungFish
05-09-2004, 11:55 AM
Thought that too, though it really wasn't working for me.
Though i did get it to do what i wanted using a Nested If statement (correct definition?)

heres what i got


<% if (String(Request.QueryString("Section")) == "" || String(Request.QueryString("Section")) == "undefined"){//open%>
<% if (String(Request.QueryString("additional"))==""||String(Request.QueryString("additional"))=="undefined"){//open%>
<html>Appropriate content</html>
<% }//close%>
<%}//close%>


--

Checks to see wether the QueryString Section is empty, or undefined; then runs second if statement to check wether QueryString Additional is empty, or undefined: if true, then display; else, do nothing i guess.

Well thanks for the help anyhow; was good seeing different techniques, hope to see you round.

Im going to make a backup before i f*** up!!

Thanks:D

David Harrison
05-09-2004, 02:23 PM
If you have some server-side code that works, don't mess with it. There's no need to keep to the standards because it only has to work on one machine.

FarFlungFish
05-09-2004, 02:45 PM
:D

well i got it working perfectly now. Good words, i will remember them.

I really should start reading some of my books again; it has been a while; its certainly not like riding a bike anyway!

see you around and thanks for the help ;)

David Harrison
05-09-2004, 02:47 PM
Happy to help. :)