This topic is locked

Dynamic form fields

4/22/2011 8:09:26 AM
ASPRunnerPro General questions
A
ASPFan author

Hi
I have an input form whether users enter details regarding a system change control. Near the end of the form I have three fields:

'Approved ?'

'Approved By'

'Approved Date'
The 'Approved ?' field is a tick box where the approver indicates whether he has approved the form details or not. The 'Approved By' and

'Approved Date' fields are readonly fields.

What I want to happen is that when the approver ticks the 'Approved ?' tick box the 'Approved BY' field auto populates with the users name or network account (session("userid") and the 'Approved Date' field auto populates with the current date.

Equally when the 'Approved ?' tick box is unticked I want the 'Approved By' and 'Approved Date' fields to be blank.

I need this to happen dynamically on the form before the user pressess any save button.
Any ideas on how I could do this would be most appreciated.
Thanks and regards,

Brian

Sergey Kornilov admin 4/22/2011

You can use something like this in BeforeAdd event:

if values("Approved ?")=1 then

values("Approved By")=Session("UserID")

values("Approved Date")=Now()

else

values("Approved By")=""

values("Approved Date")=""

end if
A
ASPFan author 4/23/2011

Thanks for the reply.

However I don;t think you understand completely what I was looking for.

I want the values of the 'Approved By' and 'Approved Date' fields to update immediately when the 'Approved ?' field is ticked or unticked...

The sample code you have supplied will only update the 'Approved By' and 'Approved Date' when the 'Save' button is pressed.

Any ideas?
Thanks,

Brian

Sergey Kornilov admin 4/23/2011

It's going to be more complicated than that in this case. You going to use Javascript API implement onchange handler of 'Approved ?' field to update other fields. You going to keep the server side code I supplied as well if you want to save those fields in the database.
A few links that can help:

http://xlinesoft.com/asprunnerpro/docs/show_dropdown_list_of_us_states.htm

http://xlinesoft.com/asprunnerpro/docs/javascript_api.htm
To pass Session("UserID") value to Javascript code check this article:

http://xlinesoft.com/asprunnerpro/docs/how_to_access_asp_variables.htm