Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

ASP - Can't change the correct hidden field in loop.

LEGEND ,
Oct 29, 2006 Oct 29, 2006
I have a table with a repeating region in ASP. In the table there are a
dropdown menu and a hiddenfield (amongst other items). I have a javascript
function that is applied to the onChange event of the dropdown menu. The
function updates the value of the hidden field to 'Y' when the dropdown
changes. The default value is 'N'.

The problem I have is that I cannot get the correct hidden field in the
repeat region to update. It always updates the hidden field in the very
first row of the repeated table even though I am changing the dropdown that
is in row no.3 for example. I know that the this is happening as I currently
have the hidded fields set to display as textfields.

Could somebody please show me how I can get the correct hidden field in the
row that holds the changed dropdown to update please.


TOPICS
Server side applications
593
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 30, 2006 Oct 30, 2006
Sounds like all your form fields have the same name, or the behavior in your
onChange event is not changing field names with everything else.


"SteveG" <ssdfsd@sdfsd.com> wrote in message
news:ei2l81$a5r$1@forums.macromedia.com...
>I have a table with a repeating region in ASP. In the table there are a
>dropdown menu and a hiddenfield (amongst other items). I have a javascript
>function that is applied to the onChange event of the dropdown menu. The
>function updates the value of the hidden field to 'Y' when the dropdown
>changes. The default value is 'N'.
>
> The problem I have is that I cannot get the correct hidden field in the
> repeat region to update. It always updates the hidden field in the very
> first row of the repeated table even though I am changing the dropdown
> that is in row no.3 for example. I know that the this is happening as I
> currently have the hidded fields set to display as textfields.
>
> Could somebody please show me how I can get the correct hidden field in
> the row that holds the changed dropdown to update please.
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 30, 2006 Oct 30, 2006
Hi Lionstone,

No, all the formfields on the form are named differently and each hidden
field (the ones in which the value can change) are named independently by
taking their value from the loop count. The behaviour will be activated
after the table is generated - when the user clicks on a dropdown in a
specific row.

I am almost sure that this is a naming problem though. I know how to name
the hidden field differently with each loop when the table is generated but
when the javascript function is called it will only see the hidden field in
the very first row of the table I do not know a method of how I can get the
HF that is in the same row as the dropdown that is accessed to change.


"Lionstone" <HIDElionstone@HIDEhushmail.com> wrote in message
news:ei51hm$3s7$1@forums.macromedia.com...
> Sounds like all your form fields have the same name, or the behavior in
> your onChange event is not changing field names with everything else.
>
>
> "SteveG" <ssdfsd@sdfsd.com> wrote in message
> news:ei2l81$a5r$1@forums.macromedia.com...
>>I have a table with a repeating region in ASP. In the table there are a
>>dropdown menu and a hiddenfield (amongst other items). I have a javascript
>>function that is applied to the onChange event of the dropdown menu. The
>>function updates the value of the hidden field to 'Y' when the dropdown
>>changes. The default value is 'N'.
>>
>> The problem I have is that I cannot get the correct hidden field in the
>> repeat region to update. It always updates the hidden field in the very
>> first row of the repeated table even though I am changing the dropdown
>> that is in row no.3 for example. I know that the this is happening as I
>> currently have the hidded fields set to display as textfields.
>>
>> Could somebody please show me how I can get the correct hidden field in
>> the row that holds the changed dropdown to update please.
>>
>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 30, 2006 Oct 30, 2006
Would it help if I posted my code? It is quite a large page though.


"SteveG" <jghj@h.com> wrote in message
news:ei54hv$7e8$1@forums.macromedia.com...
> Hi Lionstone,
>
> No, all the formfields on the form are named differently and each hidden
> field (the ones in which the value can change) are named independently by
> taking their value from the loop count. The behaviour will be activated
> after the table is generated - when the user clicks on a dropdown in a
> specific row.
>
> I am almost sure that this is a naming problem though. I know how to name
> the hidden field differently with each loop when the table is generated
> but when the javascript function is called it will only see the hidden
> field in the very first row of the table I do not know a method of how I
> can get the HF that is in the same row as the dropdown that is accessed to
> change.
>
>
> "Lionstone" <HIDElionstone@HIDEhushmail.com> wrote in message
> news:ei51hm$3s7$1@forums.macromedia.com...
>> Sounds like all your form fields have the same name, or the behavior in
>> your onChange event is not changing field names with everything else.
>>
>>
>> "SteveG" <ssdfsd@sdfsd.com> wrote in message
>> news:ei2l81$a5r$1@forums.macromedia.com...
>>>I have a table with a repeating region in ASP. In the table there are a
>>>dropdown menu and a hiddenfield (amongst other items). I have a
>>>javascript function that is applied to the onChange event of the dropdown
>>>menu. The function updates the value of the hidden field to 'Y' when the
>>>dropdown changes. The default value is 'N'.
>>>
>>> The problem I have is that I cannot get the correct hidden field in the
>>> repeat region to update. It always updates the hidden field in the very
>>> first row of the repeated table even though I am changing the dropdown
>>> that is in row no.3 for example. I know that the this is happening as I
>>> currently have the hidded fields set to display as textfields.
>>>
>>> Could somebody please show me how I can get the correct hidden field in
>>> the row that holds the changed dropdown to update please.
>>>
>>
>>
>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 30, 2006 Oct 30, 2006
Post just the loop that draws the table.

"SteveG" <jghj@h.com> wrote in message
news:ei54ll$7i6$1@forums.macromedia.com...
> Would it help if I posted my code? It is quite a large page though.
>
>
> "SteveG" <jghj@h.com> wrote in message
> news:ei54hv$7e8$1@forums.macromedia.com...
>> Hi Lionstone,
>>
>> No, all the formfields on the form are named differently and each hidden
>> field (the ones in which the value can change) are named independently by
>> taking their value from the loop count. The behaviour will be activated
>> after the table is generated - when the user clicks on a dropdown in a
>> specific row.
>>
>> I am almost sure that this is a naming problem though. I know how to name
>> the hidden field differently with each loop when the table is generated
>> but when the javascript function is called it will only see the hidden
>> field in the very first row of the table I do not know a method of how I
>> can get the HF that is in the same row as the dropdown that is accessed
>> to change.
>>
>>
>> "Lionstone" <HIDElionstone@HIDEhushmail.com> wrote in message
>> news:ei51hm$3s7$1@forums.macromedia.com...
>>> Sounds like all your form fields have the same name, or the behavior in
>>> your onChange event is not changing field names with everything else.
>>>
>>>
>>> "SteveG" <ssdfsd@sdfsd.com> wrote in message
>>> news:ei2l81$a5r$1@forums.macromedia.com...
>>>>I have a table with a repeating region in ASP. In the table there are a
>>>>dropdown menu and a hiddenfield (amongst other items). I have a
>>>>javascript function that is applied to the onChange event of the
>>>>dropdown menu. The function updates the value of the hidden field to 'Y'
>>>>when the dropdown changes. The default value is 'N'.
>>>>
>>>> The problem I have is that I cannot get the correct hidden field in the
>>>> repeat region to update. It always updates the hidden field in the very
>>>> first row of the repeated table even though I am changing the dropdown
>>>> that is in row no.3 for example. I know that the this is happening as I
>>>> currently have the hidded fields set to display as textfields.
>>>>
>>>> Could somebody please show me how I can get the correct hidden field in
>>>> the row that holds the changed dropdown to update please.
>>>>
>>>
>>>
>>
>>
>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 30, 2006 Oct 30, 2006
The problem is right at the top. :)

> <script language="javascript">
> function change() {
> document.frmSchedule.Change<%=Repeat1__index%>.value = 'Y';
> }
> </script>

This function is what you're calling in all instances inside your loop.
However, the function is only created one time; at that time, Repeat1__index
is at its initial value. You have to pass the index in to the function as a
parameter.

<script type="text/javascript">
function change(loopIndex)
{
document.frmSchedule.elements["Change"+loopIndex].value = 'Y';
}
</script>

Then the call would look like this:
onChange="change('<%=Repeat1__index%>')"



Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 30, 2006 Oct 30, 2006
I am not sure I fully understand - what is loopIndex? is this another
counter I need to place inside my loop?

"Lionstone" <HIDElionstone@HIDEhushmail.com> wrote in message
news:ei5s4t$63k$1@forums.macromedia.com...
> The problem is right at the top. :)
>
>> <script language="javascript">
>> function change() {
>> document.frmSchedule.Change<%=Repeat1__index%>.value = 'Y';
>> }
>> </script>
>
> This function is what you're calling in all instances inside your loop.
> However, the function is only created one time; at that time,
> Repeat1__index is at its initial value. You have to pass the index in to
> the function as a parameter.
>
> <script type="text/javascript">
> function change(loopIndex)
> {
> document.frmSchedule.elements["Change"+loopIndex].value = 'Y';
> }
> </script>
>
> Then the call would look like this:
> onChange="change('<%=Repeat1__index%>')"
>
>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 30, 2006 Oct 30, 2006

"SteveG" <ssdfsd@sdfsd.com> wrote in message
news:ei5sni$6o0$1@forums.macromedia.com...
>I am not sure I fully understand - what is loopIndex? is this another
>counter I need to place inside my loop?

No, it's a parameter. You pass the value of the repeat region's index
(which you're using to differentiate your form fields) to the javascript
function so it knows which fields to manipulate. loopIndex is simply the
name I gave to the parameter.

I gave you an example of how to call the function, too; you'll see that it
just uses the same index you've been using all along.

Do this long enough and the difference between client side and server side
functions won't be so hard on you anymore. ;)
Until then, folks like me will try to keep the pain to a minimum.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 30, 2006 Oct 30, 2006
So, I simply just change my existing code to what you have shown me here? I
don't have access to the PC that this resides on at the moment so I cannot
test for a couple of hours but is that all I need to do?

"Lionstone" <HIDElionstone@HIDEhushmail.com> wrote in message
news:ei60f1$aql$1@forums.macromedia.com...
>
> "SteveG" <ssdfsd@sdfsd.com> wrote in message
> news:ei5sni$6o0$1@forums.macromedia.com...
>>I am not sure I fully understand - what is loopIndex? is this another
>>counter I need to place inside my loop?
>
> No, it's a parameter. You pass the value of the repeat region's index
> (which you're using to differentiate your form fields) to the javascript
> function so it knows which fields to manipulate. loopIndex is simply the
> name I gave to the parameter.
>
> I gave you an example of how to call the function, too; you'll see that it
> just uses the same index you've been using all along.
>
> Do this long enough and the difference between client side and server side
> functions won't be so hard on you anymore. ;)
> Until then, folks like me will try to keep the pain to a minimum.
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 31, 2006 Oct 31, 2006

"SteveG" <ssdfsd@sdfsd.com> wrote in message
news:ei64ci$etl$1@forums.macromedia.com...
> So, I simply just change my existing code to what you have shown me here?
> I don't have access to the PC that this resides on at the moment so I
> cannot test for a couple of hours but is that all I need to do?

Replace the javascript function and the onChange event handler, yes.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 01, 2006 Nov 01, 2006
Hi Lionstone,

This does as you say (thankyou) and works in changing the value of the
hidden field. The problem I have now is that the update on the next page
does not work. The SQL is in a stored procedure and worked ok before. It
doesn't error it just doesn't update anything. I wonder whether this is due
to changes I made to the field?

If you have time, would you be so kind as to give me a sample of the code
you would expect to see on the update page that calls the Stored Proc so I
can compare field names etc to the code I have at the moment.

Thankyou.



"Lionstone" <HIDElionstone@HIDEhushmail.com> wrote in message
news:ei7mr1$c6b$1@forums.macromedia.com...
>
> "SteveG" <ssdfsd@sdfsd.com> wrote in message
> news:ei64ci$etl$1@forums.macromedia.com...
>> So, I simply just change my existing code to what you have shown me here?
>> I don't have access to the PC that this resides on at the moment so I
>> cannot test for a couple of hours but is that all I need to do?
>
> Replace the javascript function and the onChange event handler, yes.
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 01, 2006 Nov 01, 2006
Actually, there's a very good example of how this kind of update typically
looks over at www.drdev.net.
They use a plain-text query, so they create and destroy the command object
in every iteration of the loop. That's the one thing I'd change. Construct
your command object OUTSIDE the loop, and leave the values off of your
parameters. Then, for each loop iteration, you'd just have

myCommand.Parameters("@myParam").Value = Request.Form("myParam"&X)

Using your command name, parameter names, and loop variable, of course. :)
Just do that for every parameter, execute, and loop.

Then destroy the object after the loop. Dr Dev is correct in creating a new
object each pass using plain-text queries like that, but it's the wrong
approach with a stored procedure or parameterized SQL.


"SteveG" <jghj@h.com> wrote in message
news:ei9sl5$22p$1@forums.macromedia.com...
> Hi Lionstone,
>
> This does as you say (thankyou) and works in changing the value of the
> hidden field. The problem I have now is that the update on the next page
> does not work. The SQL is in a stored procedure and worked ok before. It
> doesn't error it just doesn't update anything. I wonder whether this is
> due to changes I made to the field?
>
> If you have time, would you be so kind as to give me a sample of the code
> you would expect to see on the update page that calls the Stored Proc so I
> can compare field names etc to the code I have at the moment.
>
> Thankyou.
>
>
>
> "Lionstone" <HIDElionstone@HIDEhushmail.com> wrote in message
> news:ei7mr1$c6b$1@forums.macromedia.com...
>>
>> "SteveG" <ssdfsd@sdfsd.com> wrote in message
>> news:ei64ci$etl$1@forums.macromedia.com...
>>> So, I simply just change my existing code to what you have shown me
>>> here? I don't have access to the PC that this resides on at the moment
>>> so I cannot test for a couple of hours but is that all I need to do?
>>
>> Replace the javascript function and the onChange event handler, yes.
>>
>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 02, 2006 Nov 02, 2006
LATEST
Thanks for all your help Lionstone and that is a really usefull document. I
just have one final request though. This problem I have with the update not
happening since I added your code is due, I am sure, to the name of the
'Change' field being passed to the parameter in the stored proc.

Can you tell me how I should reference this field when passing it to the
stored proc? The proc will only update the record if this value = 'Yes' and
I am sure that it just can't see it as I have it at the moment.

Thankyou.


"Lionstone" <HIDElionstone@HIDEhushmail.com> wrote in message
news:eiac6q$jbn$1@forums.macromedia.com...
> Actually, there's a very good example of how this kind of update typically
> looks over at www.drdev.net.
> They use a plain-text query, so they create and destroy the command object
> in every iteration of the loop. That's the one thing I'd change.
> Construct your command object OUTSIDE the loop, and leave the values off
> of your parameters. Then, for each loop iteration, you'd just have
>
> myCommand.Parameters("@myParam").Value = Request.Form("myParam"&X)
>
> Using your command name, parameter names, and loop variable, of course. :)
> Just do that for every parameter, execute, and loop.
>
> Then destroy the object after the loop. Dr Dev is correct in creating a
> new object each pass using plain-text queries like that, but it's the
> wrong approach with a stored procedure or parameterized SQL.
>
>
> "SteveG" <jghj@h.com> wrote in message
> news:ei9sl5$22p$1@forums.macromedia.com...
>> Hi Lionstone,
>>
>> This does as you say (thankyou) and works in changing the value of the
>> hidden field. The problem I have now is that the update on the next page
>> does not work. The SQL is in a stored procedure and worked ok before. It
>> doesn't error it just doesn't update anything. I wonder whether this is
>> due to changes I made to the field?
>>
>> If you have time, would you be so kind as to give me a sample of the code
>> you would expect to see on the update page that calls the Stored Proc so
>> I can compare field names etc to the code I have at the moment.
>>
>> Thankyou.
>>
>>
>>
>> "Lionstone" <HIDElionstone@HIDEhushmail.com> wrote in message
>> news:ei7mr1$c6b$1@forums.macromedia.com...
>>>
>>> "SteveG" <ssdfsd@sdfsd.com> wrote in message
>>> news:ei64ci$etl$1@forums.macromedia.com...
>>>> So, I simply just change my existing code to what you have shown me
>>>> here? I don't have access to the PC that this resides on at the moment
>>>> so I cannot test for a couple of hours but is that all I need to do?
>>>
>>> Replace the javascript function and the onChange event handler, yes.
>>>
>>
>>
>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines