Question

I'm doing a school project where, in simple terms, I have to submit data into a database and the data I want to submit is being dynamically generated and assigned to the id of divs/inputs. I know I can use request.form in ASP to retrieve data but this only retrieves the inputted data of the input (i.e. the text inside of a textarea, not the text area's id, which is what I want) Has anyone got any ideas as to how I would request the div's i.d in asp? Sorry if i'm not 100% clear. I.e. if we had an input:

<input type="textarea" name="firstname" id="1"></input>

how would I request the I.D so the retrieved data is 1, not what the user inputs into the text area.

Was it helpful?

Solution 2

Any option would have to be done client side as you cannot do this on the server without modifying the html form.

  1. Modify the name to include the id when the form is generated name="firstname_1" and extract it in the postback.

  2. Add fixed hidden inputs containing the id value:

    <input type="hidden" name="firstname_id" value="1">

  3. Intercept the post and either set the value of a previously empty hidden input, or if as you say to don't care about the text-area content replace its value with its id.

   <form name="frm" onsubmit="process();">
   ...
    
   function process()
   {
       document.frm.firstname.value = document.frm.firstname.id;
   }

Note that numeric ids are only valid in HTML5.

OTHER TIPS

You can enumerate the Form object...

(NB: enumerating is the process of assigning or retrieving a value for something).

<%
dim lc
for each lc in request.form
    response.write(lc & " = <span style='color:#77a;'>" & request.form(lc) & "</span><br />")
next
%>

In the case above the value held in lc is the ID of the control posted back to the page.

The process is also the same for query strings. If you need to find out the details of the various query strings available modify the code above to request the information from the QueryString paired value set...

<%
dim lc
for each lc in request.form
    response.write(lc & " = <span style='color:#77a;'>" & request.form(lc) & "</span><br />")
next
%>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top