Difference between revisions of "Select Check Boxes by Default"

From SmartWiki
Jump to: navigation, search
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
 
If you want to have one or more [[Custom Field Type: Select Many – Check Boxes|Check Boxes]] selected by default you need to create a [[Browser Script]] to select the boxes.
 
If you want to have one or more [[Custom Field Type: Select Many – Check Boxes|Check Boxes]] selected by default you need to create a [[Browser Script]] to select the boxes.
  
Line 6: Line 5:
 
The following will check the 2nd and 4th options for [[Custom Field]] number 568279.
 
The following will check the 2nd and 4th options for [[Custom Field]] number 568279.
 
<pre>
 
<pre>
function DefaultChecked()
+
//This is to add the newonload function to the onload function so it runs when the page is loaded
{
+
var oldonload = window.onload;
 +
if (typeof window.onload != 'function')window.onload = newonload;
 +
else {
 +
  window.onload = function() {
 +
    oldonload();
 +
    newonload();
 +
  }
 +
}
 +
 
 +
//This is the relevant function:
 +
function newonload(){
 
var frm=document.form1;
 
var frm=document.form1;
if (frm.opportunityid.value==0)
+
if(frm){
  {
+
  if (frm.opportunityid.value==0){
  frm.cf_568279[2].checked = true;
+
    frm.cf_568279[2].checked = true;
  frm.cf_568279[4].checked = true;
+
    frm.cf_568279[4].checked = true;
 +
    }
 
   }
 
   }
 
}
 
}
DefaultChecked()
 
 
</pre>
 
</pre>
  

Latest revision as of 11:52, 15 April 2010

If you want to have one or more Check Boxes selected by default you need to create a Browser Script to select the boxes.


Example: The following will check the 2nd and 4th options for Custom Field number 568279.

//This is to add the newonload function to the onload function so it runs when the page is loaded
var oldonload = window.onload;
if (typeof window.onload != 'function')window.onload = newonload;
else {
  window.onload = function() {
    oldonload();
    newonload();
  }
}

//This is the relevant function:
function newonload(){
var frm=document.form1;
if(frm){
   if (frm.opportunityid.value==0){
     frm.cf_568279[2].checked = true;
     frm.cf_568279[4].checked = true;
     }
   }
}


Note:

  • At Level 2 or 3 use document.frmevent instead of document.form1 and eventid instead of opportunityid