If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

Drop-down seemingly invisible to form

I have been asked to help out with code for our basketball web site.

This uses a single, generic HTML page which gets INCLUDEd by the ASP page. It then calls a Sub in the ASP code called BuildPage which creates the HTML and then uses Response.Write to show the page. Now, there is a drop-down (d/d) which displays season names (e.g. "1994/1995", "1995/1996") so that different results or statistics can be displayed. This d/d is "sent" to a SPAN (using '.innerHTML') contained in the HTML file. This is so that all the ASP pages can display different text in a table header. The problem seems to be that, no matter what I try, the d/d - although visible on the rendered page - doesn't seem to exist as far as the form is concerned. When the 'onChange' event occurs, it calls code that reloads the ASP with the requested season number. However, on selecting a season, I get "Object required: 'document.getElementById(...)'" for the line containing the d/d name.

A clue might be that the actual code appears on the page when viewed in 'View Source', although as I say, the d/d is rendered on the page OK.

I read elsewhere that, owing to a quirk in IE, rather than use 'innerHTML' I need to use 'createElement' and 'setAttribute' etc. to build the d/d. I went through the pain of building that (that code writes a new 'SCRIPT' section and then calls the dynamically-created Sub) but the end result is exactly the same.

I have attached what I hope are all the required files in 2 ZIPs (to bypass the 50K size restriction. The various flavours of the 'GetSeasonInfo' Sub in 'statistics.asp' will show you what I've tried.

Lastly, can we P L E A S E avoid any comment about the use of tables, VBScript versus JavaScript, coding style and so on. I just want to get this done. We will think about a re-write when we have more time. Having said that, if anyone has reasonably easy-to-follow JS, I can probably use that or massage it into VBS (which is the original coder's preferred language).

Ummm...and how are we supposed to actually test/debug this when we don't have your database?

So you are saying that, when a season is selected in the <select> and the onchange is called, that's when you have the problem? And you are also saying that it seems that the problem is that the code triggered by the onchange can't "find" the <select>?

So why not bypass the problem completely and just pass a *reference* to the <select> as part of the process.

I left out the d/b because it contains member's contact details, their passwords, etc. I figured that if someone wanted to run the actual code, it would be trivial to knock up an array of just 2 items and plug that in. If it would help, I can do that.

I went with the last option, passing the season index. Now, though, it's as if the 'onChange' event isn't happening at all! The seelction changes, obviously, but no code executes. I've put a 'MsgBox intSeasonIndex' in there to see if maybe the index wasn't being passed but that doesn't get run. I've tried using 'Me.SelectedIndex + 1', 'lisSeason.SelectedIndex + 1', even 'document.forms("frmStatistics").lisSeason.SelectedIndex + 1'

I actually prefer the way the code looks now (after the above changes) but I'm now thinking that there might be a way to write the script earlier, so that it gets written before the table. You can see I had an attempt before, using the 'spanDynamicCode' span in the generci HTML file. The problem I hit there was the d/d appeared in that span, rather than in the "header" and still failed with the original problem!

I went with the last option, passing the season index. Now, though, it's as if the 'onChange' event isn't happening at all! The seelction changes, obviously, but no code executes. I've put a 'MsgBox intSeasonIndex' in there to see if maybe the index wasn't being passed but that doesn't get run.

Time to start debugging. Clearly there is a scripting error here.

You can start by using something like:

Code:

<select ... onchange="vbscript: msgbox me.selectedIndex">

To see if the vbscript is even being triggered. It may be that the browser doesn't like to see mixed vbscript and jscript in the same tag; I've never tried that. (Your onmouseover uses javascript, you might notice.)

is the one being actioned. Then, on the client-side code, the content of the variable 'intSeasonIndex' is "[object]", a string or, more likely, an object which is coerced into a string by the runtime. From my reading, that's down to the use of GetRef which is the only way to dynamically get the Sub to run using VBScript.

Next stage...research doing the same thing but in JavaScript :-(

BTW, the JavaScript parts of the code (used for presenting tooltips) are commented-out for now but I can tell you that mixed VBS and JS work flawlessly elsewhere :-)

If you want to do it by attaching an event handler, later, using [icode]oblElement.onchange[icode] you would use an anonymous function in JavaScript, but I'm not sure there is a way to use Me in that way in VBScript.

But what I am mystified about: If you can't *FIND* the <select> then how are you managing to use objElement.onchange to attach the even to the un-findable <select>????

If you can find it to do the attachment, why can't you use the same code during the event handling?

EDIT: Never mind. I get it. objElement is happening as you are *CREATING* the <select>. DOH on me. Sorry.

I switched to using JS for the dynamic part and that has removed the problem with just getting the "[object]" string. However, the problem then was that page would continually reload, because the 'onchange' event was being triggered by the adding of the drop-down's options. So now the code creates 2 separate scripts, both now in JS: one to create the d/d and on to attach the 'onchange' event to it. I have to use this route, apparently, because IE ignores changes to elements like d/d when they're created using the '.innerHTML' property and my testing early on with this page confirms that.

- any elements in pages I build have an ID as well as a name;
- it's curious that, when the source is viewed, the rendered page shows the code to create the d/d (which appears correctly) rather than the HTML to produce it.

>Why not simply:
If you look in the ASP page, that's pretty much exactly what it does, except in VBS, rather than JS. What you see in STATS.HTM is the code which gets "rendered" after the ASP has built it and the client has run it. Again, I have to wonder how it is that the d/d appears on the rendered page but none of the HTML that created it appears when you 'View Source'!

>why you can't do this in the ASP code.
I can. And did, using the 'InnerHTML property, but the onChange event didn't seem to ever fire. I read - in several posts on other fora - that this is yet another IE quirk and that, to get it to work, you had to use the convoluted route we now have.

If I move the d/d so that it appears along with the rest of the HTML - i.e. not in the "header" row (where it says 'Statistic for Season [d/d]') - it works just fine and this is how it used to work when the site was built using an HTML "container" file and a companion ASP file to populate the HTML page. The author then decided to consolidate the twelve HTML pages into one, a worthy enough desire.

So my choices are:
- reposition the d/d and "draw" it in ASP
- abandon the whole thing

We don't really want to do change the position, because we'd end up with an odd, wasted line on the rendered page and quite a bit of work in the ASP re-doing the tables (I know, I know!!). As for abandonment, well, I'm not one to give up so easily. I remember being told that one couldn't script the link-ordering of Group Policy objects. Ha!