Add general function to set variables from the frontend
authorJoey Schulze <joey@infodrom.org>
Thu, 4 Mar 2010 14:34:02 +0000 (15:34 +0100)
committerJoey Schulze <joey@infodrom.org>
Thu, 4 Mar 2010 14:34:02 +0000 (15:34 +0100)
lib/functions.js

index da031ea..d575cb6 100644 (file)
@@ -71,6 +71,25 @@ function set_value(id, value)
                obj.selectedIndex = i;
 }
 
+function setvar(obj, name, callback, status)
+{
+    if (!obj.options[obj.selectedIndex].value.length)
+       value = -1;
+    else
+       value = obj.options[obj.selectedIndex].value;
+
+    var source = document.getElementById('source');
+
+    if (!source) return false;
+
+    var parms = 'source=' + source.innerHTML + '&name=' + name + '&value=' + value;
+
+    ajax_request('setvar', parms, callback);
+
+    if (typeof status == 'function')
+       status(obj,value,obj.options[obj.selectedIndex].innerHTML);
+}
+
 /*
  * Form functions
  */