/    Sign up×
Community /Pin to ProfileBookmark

Show Fieldsets

Hi,

This is my page:

[url]http://www.mailmypost.com/register.php#[/url]

And this is the code that I am using to show/hide fieldsets. It has been adapted from some code that Jeremy Keith wrote to show hide divs.

[CODE]
function showSection(id) {
var fieldsets = document.getElementsByTagName(“fieldset”);
for (var i=0; i<fieldsets.length; i++ ) {
if (fieldsets[i].className.indexOf(“section”) == -1) continue;
if (fieldsets[i].getAttribute(“id”) != id) {
fieldsets[i].style.display = “none”;
} else {
fieldsets[i].style.display = “block”;
}
}
}

function prepareFormNav() {
if (!document.getElementsByTagName) return false;
if (!document.getElementById) return false;
if (!document.getElementById(“formNav”)) return false;
var nav = document.getElementById(“formNav”);
var links = nav.getElementsByTagName(“a”);
for (var i=0; i<links.length; i++ ) {
var sectionId = links[i].getAttribute(“href”).split(“#”)[1];
if (!document.getElementById(sectionId)) continue;
document.getElementById(sectionId).style.display = “none”;
links[i].destination = sectionId;
links[i].onclick = function() {
showSection(this.destination);
return false;
}
}
}

addLoadEvent(prepareFormNav);
[/CODE]

Anyone see where I am going wrong? Can it even be done with fieldsets?

Cheers

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@KravvitzAug 15.2006 — The links need to point to the fieldsets.

&lt;ul id="formNav"&gt;
&lt;li id="formPersonal"&gt;&lt;a href="#personalDets"&gt;&lt;strong&gt;Personal Details&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;

<i> </i> &lt;li id="formAddress"&gt;&lt;a href="#addressDets"&gt;&lt;strong&gt;Address Details&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
<i> </i>&lt;/ul&gt;

P.S. Why did you put IDs on the <li>s? Why are you using <strong> elements there?
Copy linkTweet thisAlerts:
@NickToyeauthorAug 15.2006 — Cheers for that.

I have put id's on the li to show the icons for that particular element and I have used strong so it is an extra hook to style the text.
×

Success!

Help @NickToye spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...