Link to home
Start Free TrialLog in
Avatar of michael el halabi
michael el halabiFlag for France

asked on

asp (active server pages) postback goes to a form anchor

I know it's kind oldy to use ASP (active server pages) in 2017 but my customer site is built in asp and he does not want to change it.

He asked me to do a form that you can see here http://www.preventys.net/shopquizz.asp

The form is working great.

My problem is with the postback function.

When postbacked, i need the window to go to the field checked and not return to the top of the page. You can for example go to the last record in the form and check yes or no, it will reload as postback, but you will be sent to the top of the page.

here after the complete code


<form id="Form_ID" name="Form_ID" method="Post" action="<%=getsess("currenturl")%>">
            <table border="1" cellpadding="5" cellspacing="2" class="TableContact">     
                <%
                dim qConn, qDBC, qSql, qRs
                dim counter : counter = 1
                shopopendatabase qdbc
                qSQl="Select * from questionnaire order by qid ASC" 
                Set qrs = qdbc.execute(qsql)
                if not qrs.eof then
                    do while not qrs.eof
                        StrQuestionLabel(counter) = qrs("question_label")
                        StrQuestionHelp(counter) = qrs("question_help")

                        ' questions principales
                    %>
                    <tr>
                        <td align="cennter" valign="middle"><h3><%=qrs("qid")%></h3></td>
                        <td width="15" align="cennter" valign="middle" style="cursor:pointer;" onClick="__TOGGLESHOWHIDE('explain_<%=qrs("qid")%>');"><img title="Cliquez ici pour en savoir plus" src="icons/icon_orders_info.png" width="15" height="15" align="absmiddle" alt="" border="0"></td>
                        <td width="100%">
                            <%= Serror_q(counter)%>
                            <h3><%=StrQuestionLabel(counter)%></h3>
                            <input type="hidden" name="QL_<%=qrs("qid")%>" value="<%=StrQuestionLabel(counter)%>">
                        </td>
                        <td nowrap><input name="q_<%=qrs("qid")%>" type="radio" value="100"     <% if request("q_"& qrs("qid")) = "100" then%> checked <%end if%> onchange="__DOPOSTBACK();">Oui</td>
                        <td nowrap><input name="q_<%=qrs("qid")%>" type="radio" value="-100"    <% if request("q_"& qrs("qid")) = "-100" then%> checked <%end if%> onchange="__DOPOSTBACK();">Non</td>
                        <% 

                        ' personne concernés
                        Select case qrs("qid")
                            case "1","2","3","4","13","15","17" %>
                            <td>Tous concernés <input type="hidden" name="qtc_<%=qrs("qid")%>" value="1"></td>
                            <% case else %>
                            <td nowrap>
                                <select class="selectmultiple" name="qtc_<%=qrs("qid")%>"  onchange="__DOPOSTBACK();">
                                    <option value=''>Concerné ?</option>
                                    <option value="1" <% if request("qtc_"& qrs("qid")) = "1" then response.write "selected"%> >Oui</option>
                                    <option value="0" <% if request("qtc_"& qrs("qid")) = "0" then  response.write "selected"%> >Non</option>
                                </select>
                            </td>
                        <% end select %>
                    </tr>

                    <% 
                        'revision annuelle
                        Select case qrs("qid")
                        case "1","16","15"

                        case else

                        if request("q_"& qrs("qid")) = "100" then %>
                        <tr>
                            <td colspan="2">&nbsp;</td>
                            <td bgcolor="#eaeaea" colspan="4"><%= Serror_rev(counter)%>
                                <font size="2" color=""><b>Revision annuel à jour?</b></font>
                                    <input type="radio" name="qrev_<%=qrs("qid")%>" value="100" <% if request("qrev_"& qrs("qid")) = "100" then%> checked <%end if%> onchange="__DOPOSTBACK();">Oui
                                    &nbsp;
                                    <input type="radio" name="qrev_<%=qrs("qid")%>" value="-100" <% if request("qrev_"& qrs("qid")) = "-100" then%> checked <%end if%> onchange="__DOPOSTBACK();">Non
                                <% end if %>
                            </td>
                        </tr>
                        <% end select %>

                    <tr><td colspan="6"><div id="explain_<%=qrs("qid")%>" style="display:none;"><%=  StrQuestionHelp(counter) %></div></td></tr>

                    <%
                        counter = counter + 1
                    qrs.movenext
                    loop
                end if
                qrs.close
                set qrs=nothing
                shopclosedatabase qdbc
                %>
                </table>

                <table>
                <tr>
                    <td class="ContentContact"><h3>Veuillez recopier le code de sécurité qui s'affiche dans la case ci-contre</h3></td>
                    <td class="ContentContact"><% CreateSecurityImage "securitynumber" %></td>              
                </tr>
            </table>
            <div align="center"><br /><input class="Custsubmitbtn" type="submit" name="action" value="<%=getlang("FDC013")%>"></div>
        </form>
    <br />

    <script language="javascript">    
        var $ = function (_Id){return document.getElementById(_Id);}
        var theForm = document.forms['Form_ID'];    
        if (!theForm) {theForm = document.Form_ID;}
        var __DOPOSTBACK = function(){for (var i=0; i<(arguments.length); i=i+2){$(arguments[i]).value=arguments[i+1];}theForm.submit();}
        var __TOGGLESHOWHIDE = function(_obj){$(_obj).style.display=='none'?$(_obj).style.display='block':$(_obj).style.display='none';}
         </script>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial