• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 650
  • Last Modified:

javascript onchange not firing

I am trying to implement a way to keep track of the dirty status of controls within wizard steps.
I have put a hidden field in each step to track changes and want to set this field value to "true"/"false".  I have added an onchange event to each textbox and dropdownlist, but the event doesn't fire.
I even tried adding an attribute.add to the textbox, but I still don't get the alert.
I am also using masterpages.
How do I make this work?
Thanks
Private Sub wzdContactInfo_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles wzdContactInfo.Load
      If Not Page.IsPostBack Then
         Me.txtFirstName.Attributes.Add("onchange", "javascript:setdirty('HiConInfoDirty')")
      End If
   End Sub



<asp:TextBox ID="txtFirstName" runat="server" onchange="javascript:setdirty('HiConInfoDirty');" MaxLength="50" CssClass="backyellow" EnableViewState="true" AutoPostBack="true" ></asp:TextBox>

####Javascript function

function setdirty(hifield) {
    var hi = document.getElementById(hifield);
    hi.value = "true";
    var hipage = wzdConInfo.getElementById("HiPageDirty");
    hipage.value = "true";
    alert('Set Dirty');

 }

Open in new window

0
Sheritlw
Asked:
Sheritlw
1 Solution
 
leakim971PluritechnicianCommented:
place your alert at the beggining (line 14) instead at the end
 
0
 
ansudhindraCommented:
instead of onchange, try onKeyUp or onKeyDown events..
0
 
strickddCommented:
First:

Me.txtFirstName.Attributes.Add("onchange", "alert('test')")

Didn't work? moved this outside If Not Page.IsPostback...

Next:

function setdirty(hifield) {
    alert(hifield);
 }

Alert not what expected? Fix it. Alert show? setdirty() needs to be fixed. Alert doesn't show...

Then Try:
Me.txtFirstName.Attributes.Add("onchange", "setdirty('HiConInfoDirty')")

Still nothing?

Let me know.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
strickddCommented:
"instead of onchange, try onKeyUp or onKeyDown events.."

If using these, you will have to check for Tab, Shift, Control, etc and filter them out.
0
 
SheritlwAuthor Commented:
I set the alert at the beginning of the event and it did fire.
The reason I had the alert in there was to make sure the values were being set to the hidden field.
I am wondering if it didn't show the alert was because the value was not getting set.
Should I be passing the rendered id of the hidden field, or just the name?
How can I make sure this works?
Thanks
0
 
strickddCommented:
You need to pass the rendered ID of the control. The best way to do this is via the ClientID property.

e.txtFirstName.Attributes.Add("onchange", "javascript:setdirty('" + HiConInfoDirty.ClientID + "')")
0
 
SheritlwAuthor Commented:
Thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now