Need help getting the name of a included jsp page in javascript

615 Views Asked by At

I have this code for a .jsp page:

<f:view>
<div class="portletBody">
<h:form id="editSectionForm"  onsubmit="return numCheck(document.forms[0].elements['editSectionForm:sectionTable:0:maxEnrollmentInput'].id)">




    <sakai:flowState bean="#{editSectionBean}"/>

    <t:aliasBean alias="#{viewName}" value="editSection">
        <%@ include file="/inc/navMenu.jspf"%>
    </t:aliasBean>

    <h3><h:outputText value="#{msgs.edit_section_page_header}"/></h3>

    <%@ include file="/inc/globalMessages.jspf"%>

    <t:aliasBean alias="#{bean}" value="#{editSectionBean}">
        <%@ include file="/inc/sectionEditor.jspf"%>
    </t:aliasBean>

    <t:div styleClass="act">
        <h:commandButton
            action="#{editSectionBean.update}"
            value="#{msgs.update}"
            styleClass="active"
            onclick="reEnableLimits();" />

        <h:commandButton action="overview" value="#{msgs.cancel}" immediate="true" />
    </t:div>
</h:form>
</div>
</f:view>

and I have some javascript code that runs in the /inc/sectionEditor.jspf file. In some of that code in the sectionEdtior file, I need to somehow grab the id of this form. editSectionForm. I can't hard code it because the /inc/sectionEditor.jspf code runs in more than one page.

So pretty much, I need the javascript code in /inc/sectionEditor.jspf to be able to grab the id of the form it is currently in.

i.e:

If I'm in the editSectionForm page, it'll tell me that im in that page, if I'm in addSection Form page, it'll tell me that I'm on that page.

3

There are 3 best solutions below

0
On

I'm not sure I fully understand the question. Are you trying to get the current page you are in, as in the url?

http://css-tricks.com/snippets/javascript/get-url-and-url-parts-in-javascript/

Or do you have multiple forms on the same page?

0
On

I actually figured out another way for my situation. For anyone that's ever used Sakai, they know the beast that it is.

0
On

I see you already use document.forms[0] in your jsp page, so, making assumption there is one form only, you may use the same construction inside a script section of your 'subpages' also, i.e. using document.forms[0].id will give you the id of the form.

<!DOCTYPE html>
<html>
    <body>
        <form id="editSectionForm">
            <div id="sectionEditor">
                <script type="text/javascript">
                    var formId = document.forms[0].id;
                    console.log(formId);
                </script>
            </div>
        </form>
    </body>
</html>