Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I display this section of HTML IF a variable is NOT NULL

Status
Not open for further replies.

artdirectoreric

Instructor
Jun 26, 2001
120
US
I'm learning more and more each day. My latest puzzle is How can I have my website skip a section of HTML if a variable is NULL? I have some database results that are formatted in tables that will contain some shopping cart controls, but I don't want that section displayed if there's no information to display in it. VBScript may be the best option, using an IIf statement, but I don't know if that would work for a block of HTML, like this:

IIf Item <> NULL then PUT IN THIS BLOCK OF HTML, OTHERWISE SKIP IT

This would be on an ASP page utilizing Frontpage's Database Results Wizard.

 
Ya...Vbscript is the answer......but what is the code [pc3] exactly....& about what?...forms?....if ya what forms???
So it should be somethin like this....
<%
dim b
b=-1 //boolean=null
//some code maybe here
if item<>null
b=1
//some code maybe here
if b=1
response.write(&quot;<CENTER><B>Html code here</B></CENTEER>&quot;)
%>

But all this is not exact....what is the code exactly.....& please explain what do u exactly want...!![thumbsup2]

[deejay]MatrixMind[deejay]
 
I explained this further in another technical forum. I'll copy and paste my message from there to here:

________________________________________________________

At first glance you'd think this was a database issue, but it goes beyond that. I want a section of HTML to be skipped if a certain variable in a database is null. Basically I have an e-commerce store that sells clothing. The items are grouped into outfits, so OUTFITS contains a list of IDs for individual clothing items. Those IDS are labelled TopID, VestID, JacketID, etc., etc. I have a series of tables set up parallel to the photo that lists each item associated with that picture. If the JacketID is empty then nothing is called into the table where the Jacket info would be... HOWEVER, the table still exists on the page. This isn't a huge problem right now, but I'm eventually going to add order buttons with each item and I don't want there to be a bunch of blank tables with order buttons in them. If the VestID is NULL, I just want the HTML to skip ahead to the next section and not draw the table that would contain it. Look at this example page:


It shows a few items and a few empty tables. Like I said, I can live with it now, but once I implement order buttons this is going to look very unprofessional.
________________________________________________________

I've been told on that forum that a typical If Then Else statement will do the job. I just need to see a working example. I imagine it will look something like this: (I'm not a programmer, so I'm just writing out my theory here)

<%
If JacketID <> NULL
THEN{document.write(&quot;lots and lots of html code, including code for drawing the table, the Database Results Wizard code to get the data from the Access database, the order button and the corresponding javascript for the shopping cart controls&quot;)}
ELSE{}
%>

If you look at my example page you'll see that I'll have to do this check seven or more times for the different possible items. So can anyone point me to a site that's doing this same thing?
 
I've done some research and now know that DIV means Division, as in dividing up an area of your HTML to make it its own &quot;division&quot;. I'm off to do more research.
 
while you are on that also check out SPAN -- div's near and dear brother :/

[Hammer]
Nike Failed Slogans -- &quot;Just Don't Do It!&quot;
 
So far all I can find is how to make dynamic menus and pop-up windows. There has to be a better way. If this was BASIC it'd be a snap...

10 if JACKETID<>&quot;&quot; Then GOTO 30
20 GOTO 100
30 HTML code to draw table
40 HTML code to display JACKETID
50 HTML code to display JACKETPRICE
60 HTML code to display JACKETDESCRIPTION
70 HTML code to display ADD TO CART
80 Javascript code to add item to cart
90 HTML code to finish drawing the table
100 if VESTID<>&quot;&quot; Then GOTO 120
110 GOTO 200
120 HTML code to draw table
130 HTML code to display VESTID
...

and so on and so on.

Man, it's been a while since my Vo-Tech programming days.
 
Okay, I figured out why things weren't working the way I wanted them to. It was because I had put table info OUTSIDE the DRW area. I'm experimenting with a redesign where I put everything INSIDE the DRW and it seems like it's doing what I want it to do now. I don't know if it will behave properly once I get the shopping cart script installed into the page or not, but at least I know why it was doing what it was doing. Sorry to waste everyone's time.
 
Okay, <DIV> and <SPAN> are similar. They are ways to delineate an HTML block.

Here's a partial example:

Code:
<form name=&quot;Zodiac&quot; id=&quot;Zodiac&quot;>
  <div name=&quot;Aquarius&quot; id=&quot;Aquarius&quot;><p>You're an Aquarius!</p></div>
  <div name=&quot;Cancer&quot; id=&quot;Cancer&quot;><p>You're a Cancer!</p></div>
  <div name=&quot;Pickle&quot; id=&quot;Pickle&quot;><p>You're a Pickle!</p></div>
</form>

So, ordinarily, all of these would be visible.

But say your page has an onload event:

Code:
<body onload=&quot;document.Zodiac.Aquarius.visible=false;document.Zodiac.Cancer.visible=false;document.Zodiac.Pickle.visible=false;&quot;>

Now, you load your page, but they all disappear. If your traffic is high or your machine running slow, you might see them briefly, then bamf they're gone.

Then...

Suppose you have a button:

Code:
<input type=&quot;button&quot; value=&quot;Show me Cancer!&quot; onclick=&quot;document.Zodiac.Cancer.visible=true;return true;&quot;></input>

When you push that button -- voila! -- Cancer!

Now, you obviously don't have to use a button, this is just an example of how to make the contents of a <div> tag visible and invisible. <span>'ll do the same thing. One's good for specific words and the other has an implied paragraph break.

Hope that helps!

Cheers,


[monkey] Edward [monkey]

Like Lovecraft? Know Photoshop? Got time for the Unspeakable?
 
So in my case I would need a javascript instance to test for whether or not JacketID was NULL, and if not, turn the visibility ON for the Jacket DIV, otherwise leave it invisible.

Wow. Seems like a pretty useful tool. I can think of several ways this can help some of my other sites. Thanks for the example. Hopefully I'll have time to play with it today. Thanks so much.
 
Well, presumably, the elements of your web page exist in a certain state. And presumably, that state changes and in response to that change, the visibility of something changes.

Just pick the default status (Okay, Aquarius visible, everything else invisible) and set your onload event.

Then determine what event will trigger the change (clicking a button, flipping a radio button, reloading the page manually, whatever). Figure out what you want to happen after that event fires. You might decide to take a look at a hidden control, or you might decide to see what's been typed in a text box, or you might decide to examine a cluster of radio buttons and then change the visibility of your DIVs accordingly.

It can be a very useful tool and when used judiciously, can make for a very interactive web page.

Cheers,


[monkey] Edward [monkey]

Like Lovecraft? Know Photoshop? Got time for the Unspeakable?
 
Well, it would need to be automatic instead of user-controlled. A section would be visible on a page if there was a database entry to fill it. For example, say I have several records of companies, some with additional plant locations, some without. In their listings I would have a title that says Additional Plant Locations: followed by the data from the field. Ideally I'd want to put that section of HTML in a DIV block and make it visible if the database record actually had information in that cell. So there wouldn't be any input buttons, radio buttons or anything else that the viewer could do to make something visible or invisible.
 
It's an ASP page. There's a DETAILS page that displays the company data from our database. I've read about Queries that might be able to do what I want to do... I think I can have a query search a field for info, and if it finds it it can build the title, add a <br>, then put the field info in. I'll play with that and see if it works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top