Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loop through recordset and remember each record IDq

I am using ASP Classic with VBScript on a web page. From a table I extract a recordset, the loop through it and assign the record ID to a value. When the user clicks on an article, it should post the record ID to another page, but I get a concatenated string like "1, 2 ,5, 7, 8" each number representing the record ID.

Here is the code portion where things go wrong:

<form action="restaurant.asp" method="post">
<%
Do Until rs.EOF
%> 
  <article class="img-item" onClick="submitTD()">
    <h3 class="hidden"></h3> 
    <figure >  
       <span class="thumb-screen"></span>
       <img src="<%response.Write(rs("restTopDealPic"))%>" alt="<%response.Write(rs("restTopDealTagLine"))%>"/>

        <figcaption>
          <strong>
            <%response.Write(rs("restName"))%> <br> <%response.Write(rs("restTopDealTagLine"))%>
           </strong>

           <%response.Write(rs("restTopDealDesc"))%>
        </figcaption>
     </figure>
  </article>
  <input class="hidden" name="mainTableIDS" id="mainTableIDS" value="<%response.Write(rs("MainTableID"))%>"/>
            <input type="submit" id="TDSubmit" />
        <%
  'Move to the next record (important!!)
  rs.MoveNext
Loop
%>
</form> 
        <%
rs.close
%>

Any help will be sincerely appreciated!

like image 985
PeterJ Avatar asked Feb 03 '26 20:02

PeterJ


1 Answers

  • You're not telling the html what type of input fields you want, so it's defaulting to text fields.
  • You're using the same name attribute for all said text fields. When you do that, it's considered to be a single field, and it returns a comma-delimited list of values.
  • You have no fallback for people who have javascript turned off, which can be an accessibility problem.

I think what you're after is a set of radio buttons. Unlike text fields, with a set of radio buttons all named the same thing, only the selected one's value will be returned.

<form ...>
<%
Do Until rs.EOF
    Response.Write "<article ...>"  'etc. etc. etc.
    '... figure, span, img, figcaption ...
    Response.Write "<input type='radio' name='IDs'" 'same name for all radio buttons
    Response.Write " id='id" & rs("MainTableID") & "'" 'ids must be unique
    Response.Write " value='" & rs("MainTableID") & "' />" 'only the selected value will be posted
    '--- close figcaption, etc.
    Response.Write "</article>"
    rs.Movenext
Loop
Response.Write "<input type='submit' value='Submit' />"
%>
</form>
like image 168
Martha Avatar answered Feb 05 '26 12:02

Martha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!