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
<%
Dim header : header = getlang("FDC002")
setsess "currenturl" , "shopquizz.asp"
'
'dim customerid : CustCheckAdmin customerid
'
dim strsubject
dim customeradmin, custid
Dim sAction, dbtable
dim strcomment
dim qID
dim sx
'
dim qc,qrev
'
Dim StrQQ_(17)
Dim StrQR_(17)
Dim StrQL_(17)
'
Dim StrQREV_(17)
Dim StrQREV_VAL_(17)
'
Dim StrQuestionLabel(17)
Dim StrQuestionHelp(17)
Dim StrQtc(17), StrQtc_Total
'
Dim Serror_q(17)
Dim Serror_rev(17)
Dim StrQuizzResult, StrRevQuizzResult, StrTotalPoints
'
sAction = Request("Action")
if saction = "" then
sAction = Request("Action.x")
end if
'
Serror = ""
'
' AFFICHAGE DU SITE
ShopPageHeader "ContentPageContact"
'
putMyTitle "Répondez à notre questionnaire pour savoir si votre entreprise est conforme aux lois en vigueur"
'
if sAction = "" then
DisplayForm
else
ValidateData()
if sError = "" then
Add_Quizz_to_Database
WriteInfo "<h3>Merci d'avoir répondu au questionnaire.</h3><h3>Vous recevrez dans quelques minutes un diagnostique de conformité de votre établissement.</h3>" , ""
SendMailTo_Merchant_Customer qid
else
shopwriteError SError
%><br /><%
DisplayForm
end if
end if
ShopPageTrailer
'
'*************************************************
'Display Form
'*************************************************
Sub DisplayForm()
%>
<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"> </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
<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';}
var __HIDDENLISTOJECT = function(){
for (var i=1; i<(arguments.length); i=i+2){$(arguments[i]).checked='';$(arguments[i+1]).style.display='none';}
for (var i=1; i<(arguments.length); i=i+2){$(arguments[i]).checked='';$(arguments[i]).disabled='disabled';}
if($(arguments[0]).style.display!='none')
{
$(arguments[1]).disabled='';
}
}
</script>
<%
End Sub
You can do a Achor Location Scroll, http://www.the-art-of-web.com/javascript/remove-anchor-links/#another-heading.
Put and Id for the radio buttons and pass event as parameter for onChange listener:
<td nowrap><input name="q_<%=qrs("qid")%>" id="id_<%=qrs("qid")%>" type="radio" value="100" <% if request("q_"& qrs("qid")) = "100" then%> checked <%end if%> onchange="__DOPOSTBACK(event);">Oui</td>
<td nowrap><input name="q_<%=qrs("qid")%>" id="id_<%=qrs("qid")%>" type="radio" value="-100" <% if request("q_"& qrs("qid")) = "-100" then%> checked <%end if%> onchange="__DOPOSTBACK(event);">Non</td>
so, in onChange handler you change location.href
var __DOPOSTBACK =
function(event){
var formAction = "preventys.net/shopquizz.asp" + '#' + event.target.id;
theForm.action = formAction;
theForm.submit();
}
I think this could work for you.