[pLog-svn] r5743 - in plog/trunk/js: location ui

oscar at devel.lifetype.net oscar at devel.lifetype.net
Sat Jul 28 05:21:38 EDT 2007


Author: oscar
Date: 2007-07-28 05:21:37 -0400 (Sat, 28 Jul 2007)
New Revision: 5743

Modified:
   plog/trunk/js/location/location.js
   plog/trunk/js/ui/forms.js
Log:
More standards compliant way to add an option to a select list via the DOM.


Modified: plog/trunk/js/location/location.js
===================================================================
--- plog/trunk/js/location/location.js	2007-07-27 21:55:52 UTC (rev 5742)
+++ plog/trunk/js/location/location.js	2007-07-28 09:21:37 UTC (rev 5743)
@@ -358,14 +358,10 @@
 	addNewValue = locationList.options[locationList.selectedIndex].value;	
 	
 	// add the new option
-	/*opt = document.createElement ( 'option' );
-	opt.text = locDesc;
-	opt.value = locId;
-	locationList.options[locationList.options.length - 1] = opt;*/
-	Lifetype.Forms.List.appendToList( 'locationId', locId, locDesc );
+	Lifetype.Forms.List.appendToList( 'locationId', locId, locDesc, true );
 	
 	// and select the last but one option (the new one that was added)
-	locationList.selectedIndex = locationList.options.length - 1;
+	//locationList.selectedIndex = locationList.options.length - 1;
 	
 	locationLatitude = Lifetype.Dom.$( 'locationLat' );
 	if( locationLatitude != undefined )

Modified: plog/trunk/js/ui/forms.js
===================================================================
--- plog/trunk/js/ui/forms.js	2007-07-27 21:55:52 UTC (rev 5742)
+++ plog/trunk/js/ui/forms.js	2007-07-28 09:21:37 UTC (rev 5743)
@@ -62,9 +62,12 @@
  * @param value
  * @param ite
  */
-Lifetype.Forms.List.appendToList = function( fieldName, value, item )
+Lifetype.Forms.List.appendToList = function( fieldName, value, item, selectOpt )
 {
-	return( Lifetype.Forms.List.appendToExternalList( document, fieldName, value, item ));
+	if( selectOpt == undefined )
+		selectOpt = false;
+		
+	return( Lifetype.Forms.List.appendToExternalList( document, fieldName, value, item, selectOpt ));
 }
 
 /**
@@ -76,8 +79,11 @@
  * @param value
  * @param ite
  */
-Lifetype.Forms.List.appendToExternalList = function( dest, fieldName, value, item )
+Lifetype.Forms.List.appendToExternalList = function( dest, fieldName, value, item, selectOpt )
 {
+	if( selectOpt == undefined )
+		selectOpt = false;
+	
 	dstList = dest.getElementById( fieldName );
 
 	// check if the element is already there
@@ -94,7 +100,14 @@
 	// add the element only if not found
 	if( !found ) {
 		newOpt = new Option( item, value );
-		dstList.options[dstList.options.length] = newOpt;
+		//dstList.options[dstList.options.length] = newOpt;
+		newOpt.selected = selectOpt;
+		try {
+			dstList.add( newOpt, null ); // standards compliant; doesn't work in IE
+		}
+		catch( ex ) {
+			dstList.add( newOpt ); // IE only
+		}
 	}
 
 	return true;



More information about the pLog-svn mailing list