[Javascript] Did that Dropdown change?

Scott.Wiseman swiseman at remax-cahi.com
Tue Mar 5 14:57:30 CST 2002


Any way to get the default selected option
on the dropdown object?


I can tell what is select but not what it was..
so I can not tell if it has changed...

I can do an onchange() do something...but then
I have to do this for all drop downs... I would like to make
it universal...like the textbox, the checkbox,radio buttons, etc...

any ideas???

Scott

if(myform.elements[i].type=="select-one")
     { 
     myform.output1.value =  myform.output1.value       + 'Field Name: ' +
                             myform.elements[i].name    + ' DropDown : ' +
                             myform.elements[i].selectedIndex +
                             myform.elements[i].length
+ '\r\n'; 
     }             
           

<script language =javascript> 
function dosomthing()
{

//==========================================================================
===========           
//=================Looping through the FORM to look for changes in the
elements =======
//==========================================================================
===========
	for ( i=0; i <myform.elements.length; i++ ) 
   		 {  //checking code
//==========================================================================
===========           
//=================Checking the Form for Text Changes that have been
modified =========
//==========================================================================
===========
           if(myform.elements[i].type=="text")
           {  
                 if(myform.elements[i].value !=
myform.elements[i].defaultValue)
                    {
				                myform.output1.value =
myform.output1.value       + 'Field Name: ' +
              		                         myform.elements[i].name
+ ' Changed to: ' +
                     		                  myform.elements[i].value
+ ' From: ' +
	
myform.elements[i].defaultValue    + '\r\n';  
                    } // if statement           		        
           } // if statement
//==========================================================================
===========           
//=================Checking the Form for Check Boxes that have been clicked
===========
//==========================================================================
===========
           if(myform.elements[i].type=="checkbox")
           { 
             if(myform.elements[i].defaultChecked !=
myform.elements[i].checked)
                {
                   myform.output1.value =  myform.output1.value       +
'Field Name: ' +
      		                                 myform.elements[i].name
+ ' CheckBox was: ' +
 
myform.elements[i].defaultChecked + ' Checkbox is : '+
       		                              myform.elements[i].checked   +
'\r\n'; 
                }      
           }            
           
//==========================================================================
===========           
//=================Checking the Form for SELECT box selected
==========================
//==========================================================================
===========

         if(myform.elements[i].type=="select-one")
           { 
                      myform.output1.value =  myform.output1.value       +
'Field Name: ' +
      		                                 myform.elements[i].name
+ ' DropDown : ' +
 
myform.elements[i].selectedIndex +
       		                              myform.elements[i].length

       		                                + '\r\n'; 
           
           }             
           
           
//           if(myform.elements[i].type=="textarea")
//           { alert("textarea"); }
           
          
           
           
           
           if(myform.elements[i].type=="select-multiple")
           { alert("select-multiple"); }           
           
           


           

       } // for loop

} // function

</script>



More information about the Javascript mailing list