3

I want to figure out whether the user has did any changes on the page. Below is what i am doing to achieve this. I am accessing the asp.net form elements in the javascript as below

var _totalElementsPresent = document.getElementById("aspnetForm").elements.length;
for( var i=0;i<_totalElementsPresent;i++)
  {
var _formObject = document.getElementById("aspnetForm").elements[i];
  switch(_formObject.type)
    { 

case 'select-one' :
        case 'select-multiple':
                    for (var j = 0; j < _formObject.options.length; j++) 
                    {
                    if (_formObject.options[j].selected !=_formObject.options[j].defaultSelected)
                    _flag = 1;        
                    }


  case 'radio' :
                    if (_formObject.checked != _formObject.defaultChecked) 

I am setting the radio button selected false as below

<asp:RadioButton ID="CopyRadioButton" runat="server" Text="Copy"
                                    Checked="false"/>

but _formObject.defaultChecked will be set to true.

How to set the radio button checked= false and dropdown selected= true.

1 Answer 1

1

The problem is with your if statement: Remember that _formObject.checked will be undefined if the input doesn't have a "checked" attribute. (The absence of the attribute is a valid way of indicating that the input is not checked) Try switching your if statement around:

if (_formObject.checked == _formObject.defaultChecked) 
{
    // the value has not changed
}
else
{
    // the value has changed
}

EDIT: The same goes for the select attribute on the dropdown options

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.