dynamic array to classic asp page

876 views Asked by At

I'm using classic asp. I have a form which is filled up by images taken from a db and other type of inputs. If the user clicks on one image, I need to add an item (maybe a string, maybe a number, it's not relevant) to an array and then send it to a classic asp page with all the other values in the form. My code is something like this: (in this case the array is filled by clicking a button)

<script language ="javascript">
var arr = [];
var i = 0;
function aggiungi() {
    arr.push(i.toString());                
    i++;
}

</script>

<html>
<form method ="post" action="save.asp">
    <input type ="text" name="nome" />
    <input type ="button" onclick="aggiungi()" value ="add"/>
    <input type="submit" value ="invia" />
</form>

I wanna send the value in the textbox and the array arr. How can I do?

2

There are 2 answers

0
Mark On

Along the lines of what @stephen-r was saying, this appears to be a HTML form question, not really ASP.

If the HTML Form elements have the same name, then they'll come through on the receiving page as a comma separated list. Meaning that his solution would do precisely what he says.

Where it becomes an ASP question is on the receiving page.

Personally, If I were going to use the button idea as you've described, I would probably have hidden checkboxes and use client-side JavaScript to check/uncheck them as the button (or image) is pressed.

Alternatively, if you'd like to do more work, have one hidden textbox, and use client-side JavaScript to add/remove the the contents of that textbox based on what has been pushed. (using a comma as a delimiter.)

!! Either way, the ASP page receiving the form will be seeing a comma separated list of values.

4
Stephen R On

I would try setting each image item as an HTML checkbox, using the Label element for the actual images; then CSS to hide the actual checkboxes. Also CSS to distinguish the images as checked or not.

Example:

<form method="post" action="test.asp">
    <input type="checkbox" name="images[]" value="img1.jpg">1</br>
    <input type="checkbox" name="images[]" value="img2.jpg">2</br>
    <input type="checkbox" name="images[]" value="img3.jpg">3</br>
    <input type="checkbox" name="images[]" value="img4.jpg">4</br>
    <input type="checkbox" name="images[]" value="img5.jpg">5</br>
    <input type="submit">
</form>

Click the first and third checkboxes. On submit to test.asp, request.form("images[]") = img1.jpg,img3.jpg