Help with Javascript code

Asked

Viewed 95 times

0

I don’t quite understand what you wanted to do with this code. You should open a Div with a basic form.

My code:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://cloud.github.com/downloads/digitalBush/jquery.maskedinput/jquery.maskedinput-1.3.min.js"></script>
<script src="../../Scripts/jQuery.js"></script>
<script type="text/javascript">
    var SoliciteProposta = $.noConflict();
    function MostrarEsconderDiv(div) {

        var prefixo = "ContentPlaceHolderDefault_ContentPlaceHolderDefault_ctl02_SoliciteUmaProposta_5_";
        var hdnDiv = prefixo + "hdn" + div;

        if (document.getElementById(prefixo + div).style.display == "none") {
            document.getElementById(prefixo + div).style.display = "block";
            document.getElementById(hdnDiv).value = "aberta";
        }
        else {
            document.getElementById(prefixo + div).style.display = "none";
            document.getElementById(hdnDiv).value = "";
        }
    }
</script>

<tr>
                        <td colspan="3" height="10">
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3" valign="top">
                            <div class="Section">
                                <div class="SectionHeader">
                                    <table border="0" cellpadding="0" cellspacing="0" width="100%">
                                        <tr>
                                            <td>
                                                <img align="absMiddle" hspace="4" src="/images/internas/seta3.gif" />
                                                <a id="A3" class="linkFormularios" href="javascript:MostrarEsconderDiv('divSecao6')">Para Sistema Integrado de Gestão, clique aqui</a>
                                                <%--  <asp:LinkButton ID="lbtnAbrirSecao6" runat="server" ForeColor="#cc3333" Font-Size="small" Font-Bold="true" OnClientClick="return MostrarEsconderDiv('divSecao6')">
                                            Para Sistema Integrado de Gestão, clique aqui
                                            </asp:LinkButton>
                                                --%>
                                                <br />
                                                (abrirá um formulário nesta mesma página para você preencher)
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                                <div id="spacer" style="margin-top: 5px">
                                </div>
                                <div id="divSecao6" style="display: none; margin-left: 30px" runat="server">
                                    <table id="idSecao6Table" width="100%">
                                        <!-- SECAO 6 -->
                                        <tr>
                                            <td height="15">
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="center" bgcolor="#ececec" height="21">
                                                <b>6 - Apenas para Sistema Integrado de Gestão</b>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td bgcolor="#cccccc" height="1">
                                            </td>
                                        </tr>
                                        <tr>
                                            <td height="5">
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="center" bgcolor="#f5f5f5">
                                                Responda a esta seção apenas se você estiver interessado em uma certificação integrada (opcional).
                                            </td>
                                        </tr>
                                        <tr>
                                            <td height="5">
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <font color="#666666"><b>A Política e o Manual do Sistema de Gestão são integrados?</b></font>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:RadioButtonList ID="rblPoliticaManualSistemaIntegrados" runat="server" RepeatDirection="Horizontal">
                                                    <asp:ListItem Value="Sim" Text="Sim"></asp:ListItem>
                                                    <asp:ListItem Value="Não" Text="Não"></asp:ListItem>
                                                </asp:RadioButtonList>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td height="5">
                                            </td>
                                        </tr>
                                        <tr>
                                            <td bgcolor="#cccccc" height="1">
                                            </td>
                                        </tr>
                                        <tr>
                                            <td height="5">
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <font color="#666666"><b>Os procedimentos de gestão (ex: Controle Documentos, Auditorias) são integrados?</b></font>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:RadioButtonList ID="rblProcGestaoIntegrados" runat="server" RepeatDirection="Horizontal">
                                                    <asp:ListItem Value="Sim" Text="Sim, pelo menos 80% dos procedimentos de gestão são integrados"></asp:ListItem>
                                                    <asp:ListItem Value="Não" Text="Não"></asp:ListItem>
                                                </asp:RadioButtonList>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td height="5">
                                            </td>
                                        </tr>
                                        <tr>
                                            <td bgcolor="#cccccc" height="1">
                                            </td>
                                        </tr>
                                        <tr>
                                            <td height="5">
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <font color="#666666"><b>Os procedimentos operacionais (ex: Controle de produção) são integrados?</b></font>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:RadioButtonList ID="rblProcOperacionaisIntegrados" runat="server" RepeatDirection="Horizontal">
                                                    <asp:ListItem Value="Sim" Text="Sim, pelo menos 80% dos procedimentos operacionais são integrados"></asp:ListItem>
                                                    <asp:ListItem Value="Não" Text="Não"></asp:ListItem>
                                                </asp:RadioButtonList>
                                            </td>
                                        </tr>
                                        <!-- FIM - ESCONDE SEÇÃO 6  -->
                                    </table>
                                </div>
                            </div>
                        </td>
                    </tr>
  • What’s your question exactly? The div isn’t showing up?

  • This @Fernandomedeiros, I did not understand very well what the guy wanted to do, I need to make the div visible. I want to understand and fix this code.

  • Face basically what the function does is to concatenate a string passed as parameter with a preset value and select the element with that resulting string, if the element is visible it hides, otherwise it makes appear

  • The function is called each time a click occurs on the <a id="A3" class="linkFormularios" href="javascript:Showhidediv('divSecao6')">For Integrated Management System, click here</a>

  • Oh beauty, I understood right then, only that type is not appearing when clicking on the link. How can I modify this Function so that it is visible when clicking ?

  • you should look for the html element that is grouping such a form that Voce said should appear, look for the id attribute, finding it to change the code of the Show function

  • see at which points of your application this function is called, but the fact that it concatenates the parameter string with the value Contentplaceholderdefault_contentplaceholderdefault_ctl02_requeumaproposta_5_

  • is very strange, as there will VERY rarely be an id attribute with such a long name, if your form id is simply "div6", make this string passed by the parameter to be used in the Document.getElementById function()

  • They changed the class of the div, through a method: using display: block and display:None, and changed the value of it, through variable concatenation.

Show 4 more comments

1 answer

1


What I suggest you do:

Modify the part where the string concatenation occurs to the parameter, because it is very difficult to exist any element with such an extensive id

var prefixo = "ContentPlaceHolderDefault_ContentPlaceHolderDefault_ctl02_SoliciteUmaProposta_5_";

Modify where this occurs:

document.getElementById(prefixo + div)

for:

document.getElementById(div)

Now look for the ID of the element of your form that should appear after the click of the button, and pass it as function parameter;

<a id="A3" class="linkFormularios" href="javascript:MostrarEsconderDiv('divSecao6')">Para Sistema Integrado de Gestão, clique aqui</a>
                                            <%--  <asp:LinkButton ID="lbtnAbrirSecao6" runat="server" ForeColor="#cc3333" Font-Size="small" Font-Bold="true" OnClientClick="return MostrarEsconderDiv('divSecao6')">
                                        Para Sistema Integrado de Gestão, clique aqui
                                        </asp:LinkButton>

Where is MostrarEsconder("divSecao6") exchange div6 for the id of your form element

If this does not work create a new function, copy the contents of the current function and redo the changes listed above, change the click event of your button to call this new function, and pass as parameter your form, in case I believe the ID is divSecao6

  • outside the project worked, but inside not dude. Weird.

  • Press F12 using Chrome and see the console

  • I’ve seen, nothing relevant.

  • Now I give: Uncaughttypeerror: Cannot read Property 'style' of null

  • You need to add a style attribute to the form element, put style="display:None"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.