0

I have an old ASP-page that contains a form but for some reason, a part of the code doens't work anymore. The code was working before because I write the content of the form in a database and there I have values from the past.

A short description of my page: I have a [select multiple]-field and when you select one (or more) option I create another input field (for every selected option a new fied). The ID of this field is FSRow_ + an edited value of de selected option (no spaces, commas, ...).

When I submit the form I want to read the content of my new fields so I can write this information to my database.

An example: Suppose I have two selected options, to make it easy: "OptionA" and "OptionB", then I create two new fields (from the source code):

<input name="FSRow_OptionA" id="FSRow_OptionA" type="text">
<input name="FSRow_OptionB" id="FSRow_OptionB" type="text">

When I submit my form, I have this code:

if request.form()
...
getSelectedValues = split(request("OptionList"), ",")
    for each li in getSelectedValues 
        li = replace(li, "'", "''")
        li = replace(li, "||", ",")
        fsrow = trim(request("FSRow_" & replace(replace(replace(replace(replace(trim(li), " ", ""), "&", ""), "+", ""), ",", ""), "|", "")))
        if fsrow <> "" then
            [write to DB with dynamic field]
        else
            [only write selected item]
        end if
    next

When I look in my database. I have only the information of the selected items (so, my i'm going in my else-code). Not the content of my dynamic field. So I suppose the variable "fsrow" is always empty, even if my new field contains some text.

My questions:

  1. How can I get the content of my dynamic input field?
  2. Any idea what could be wrong because it was working in july 2017 and didn't change anything.
  3. [Not needed anymore, found the solution] I've tried to set an alert or write to the console to debug but this isn't working. How can I debug when I'm in my "for each"-loop?

Edit/Update 1:

As commented by Ricardo Pontual I can use "Response.End" in combination with "Response.Write" before.

If I do this:

Response.Write(li)
Response.Write("## FSRow_" & li & " ## ")
Response.Write("->" & request("FSRow_" & li))

I get this result:

OptionA## FSRow_OptionA ## ->

But in my form/input field I wrote "test" in the field with id "FSRow_OptionA"...

Edit/Update 2:

With a non-dynamic input field I can perfectly read and write the value in my database. So it's realy a problem with the dynamic field...

endeka
  • 131
  • 1
  • 15
  • A code don't stop working "by nothing", for sure something changed.. there's another question here about how to debug classic asp: https://stackoverflow.com/questions/1138175/how-do-you-debug-classic-asp – Ricardo Pontual Mar 26 '18 at 10:58
  • Ricardo, I'm the only person who make changes in this files so I'm 100% sure the code didn't change... – endeka Mar 26 '18 at 11:03
  • When I'm talking about changes, I don't mean code only @endeka, some service pack, server update, database changes (tabele, data), there's a lot o things that can "changend" and do your code works different – Ricardo Pontual Mar 26 '18 at 11:14
  • Indeed, IE updates, ... The table didn't change. I only have a problem at this line "fsrow = trim(request("FSRow_" & replace(replace(replace(replace(replace(trim(li), " ", ""), "&", ""), "+", ""), ",", ""), "|", "")))" ... – endeka Mar 26 '18 at 11:32
  • Try to inspect the `li` variable before this line, with a `Respose.Write` for instance – Ricardo Pontual Mar 26 '18 at 11:35
  • that's the problem, response.write, alert (javascript), console logging, ... isn't working after my "if request.form()". – endeka Mar 26 '18 at 11:40
  • 1
    Even with a `Response.End` after? – Ricardo Pontual Mar 26 '18 at 11:42
  • See extra comments in my post – endeka Mar 26 '18 at 12:04

1 Answers1

0

Found the problem. This was very old code, from years ago that wasn't written by me, and the problem was the position of < form> and < /form>

Old code (NOT WORKING)

<table>
    <form>
        <tr>
        ...
        </tr>
    </form>
</table>

Changed the code by this:

<form>
    <table>
        <tr>
        ...
        </tr>
    </table>
</form>

I changed the order of < table> and < form> and it works now!

endeka
  • 131
  • 1
  • 15