Search code examples
asp-classicrequest.form

ASP request.form ID of div?


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.


Solution

  • 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.