The code below is a show/hide program - it works in in IE but for my collegues with a MAC & FF it doesn’t work, can anybody help? I never authored this code and could do it with jQuery easily but that would mean changing the page which at the moment i don’t really have time- any point in the right direction would be great:
ShowFirstHideRest = function()
{
for (var i = 0; i < arguments.length; ++i)
{
var oEl = document.all.item(arguments[i]);
if (oEl != null)
{
if (i == 0)
{
oEl.style.display = "";
}
else if (!(oEl.id == arguments[0]))
{
oEl.style.display = "none";
}
}
}
Thanks so much for your help and speedy response, I know we’re almost there but it still isn’t working. We build the select list on the fly from a users input (basically the script is used in a content management screen), the selects options relate to a table of inputs which have the ID of the number in the select box, in this case the code in the table is when V2 Cash is selected…
Can I add that it’s not such a good idea to do this kind of thing with just relying on javascript.
The way I like to do it is either using asynchronous javascript (Ajax without the XML) or preferably by using a scrollable div with the scrollbar hidden by the area’s container.
This method allows <a href=“#area_1”> to show area_1 and <a href=“#area_2”> to show area_2
No, don’t. The value visible is not valid for the display property (it is for the visibility property, but that’s something else). Setting it to an empty string is the right thing to do, since that effectively undoes the preceding display:none declaration.
The document.all thing isn’t good practice, though. It’s an IE-proprietary property, although other browsers now support it after some fashion. It would be better to use document.getElementById() if the arguments supplied are identifiers. If you’re using name attribute values that won’t work (outside IE) though.
I should explain how my version of asychronous javascript will make this work. I’m not sure if you will understand but I made a statement above that some will question. It’s in classic asp.
The menu and container for the interactive area…
<%
live=int(request.queryString("live"))
if live=1 then
response.contentType="text/javascript"
end if
function write(s)
if live=1 then
response.write replace(replace(s,"""","\\"""),vbcrlf,"")
else
response.write s
end if
end function
'----write the html for the menu if live doesn't equal 1
if live<>1 then
for i=0 to 4
response.write "<a href=""index.asp?show_subject=subject_" & i & """ title=""subject_" & i & """>Subject " & i & "</a>" & vbcrlf
next
end if
'----if live use javascript, else use html
if live=1 then
response.write "document.getElementById(""container"").innerHTML="""
else
response.write "<div id=""container"">" & vbcrlf
end if
subject=request.querystring("subject")
'----verbose----'
'----get html for requested subject and assign to var subject
' ----this will depend on whether you use text files or databases to store html
'----output subject depending on live using the write function above----'
write subject
'----close html or javascript
if live=1 then
respsonse.write """;"
else
response.write "</div>" & vbcrlf
end if
%>
If I were to click a link when javascript was turned off, it will just output the html for subject in the container. If I used this piece of javascript, it will output subject as javascript, straight into the container, live