...

View Full Version : Accessing form data within layer



dillieo
08-08-2002, 04:42 PM
Greets all,

I have a page that has a couple forms hidden within layers. I use these multiple forms to funnel to a centralized form, which then calls the primary script to grab stuff from a database.

I'm trying to get the data of a form (via simple JavaScript) from the 'biblenav' form in the 'openmenu' layer and pass it to the root form 'query'. Here's what my JavaScript looks like:

function start_nav()
{
bookindex = document.openmenu.biblenav.book_select.selectedIndex;
chapterindex = document.openmenu.biblenav.chapter_select.selectedIndex;
versionindex = document.openmenu.biblenav.version_select.selectedIndex;
commindex = document.openmenu.biblenav.notes_select.selectedIndex;
book = document.openmenu.biblenav.book_select[bookindex].value;
chapter = document.openmenu.biblenav.chapter_select[chapterindex].value;
verse = 0;
version = document.openmenu.biblenav.version_select[versionindex].value;
commtype = document.openmenu.biblenav.comm_select[commindex].value;
document.query.book.value = book;
document.query.chapter.value = chapter;
document.query.verse.value = verse;
document.query.version.value = version;
document.query.commtype.value = commtype;
document.query.submit();
}

Problem is that when I start the function. I get the error message "document.openmenu.biblenav is null or not an object"

Any thoughts would be greatly appreciated.

requestcode
08-08-2002, 05:02 PM
Is this a problem with Netscape 4 version? If it is try this:
bookindex = document.openmenu.document.biblenav.book_select.selectedIndex

brothercake
08-08-2002, 05:03 PM
in netscape 4, a layer is a document. so a form inside a layer would be

document.layername.document.formname.element.value

dillieo
08-08-2002, 05:06 PM
I'm actually running into this problem with IE 6, but thanks for the heads up on the Netscape problem. I'll need to address that next 8^D

Roy Sinclair
08-08-2002, 08:33 PM
If you're planning to go cross-browser (NS 4+, IE 4+) then you should rework the script a bit anyway:



function start_nav()
{
var lf=(document.layers) ? document.openmenu.document.biblenav : document.getElementById('biblenav');
bookindex = lf.book_select.selectedIndex;
chapterindex = lf.chapter_select.selectedIndex;
versionindex = lf.version_select.selectedIndex;
commindex = lf.notes_select.selectedIndex;
book = lf.book_select[bookindex].value;
chapter = lf.chapter_select[chapterindex].value;
verse = 0;
version = lf.version_select[versionindex].value;
commtype = lf.comm_select[commindex].value;
document.query.book.value = book;
document.query.chapter.value = chapter;
document.query.verse.value = verse;
document.query.version.value = version;
document.query.commtype.value = commtype;
document.query.submit();
}


The above code actually requires NS 4 or later and IE 5 or later (it doesn't support IE 4 but could easily have IE 4 added) but it should work with the Gecko based browsers like Mozilla 1 and Netscape 6.

Of course whether the script above works will also depend on what your HTML for this form actually looks like, the problem you're having may be caused by your html not being correct.

dillieo
08-08-2002, 09:01 PM
Thanks, that fixed it. I was just using the wrong syntax to access the elements, you way fixed everything. I also found that in IE you can access the form directly, like through just document.biblenav. But I want it cross browser, so I'm using your method. Thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum