Tuesday, June 5, 2012

Changing the Element Properties on fly , example making a field required or optional on fly


  • Create an page item in apex called AGE.
  • Add the span tag to thew item label along with the label of the item as  
  • <
    span id="P1_AGE"
    >
    Age of Customer
    :
    <
    /span
    >
Now in case you want to make the age as mandatory field depending on any other field lets call it as ...Admission_class .
In case the Admission_class field is as play school then the age is not required to be made as mandatory and in the case when admission_class is choosen as  KG then this field AGE needs to be made as mandatory.
So lets create one more item called p1_admission_Class .
Lets call a javascript on the change of the field admission_Class to make the other field as mandatory.
function show_fields_mandatory(v1)
{
if (v1=='PLAY SCHOOL')
{
// alert(v1);
var x=document.getElementById("P1_Admission_class');
x.style.color = 'red';
}
if (v1=='KG')
{
// alert(v1);
var y=document.getElementById("P1_ADMISSION_CLASS");
var x=document.getElementById("P1_AGE");
x.style.color = 'black';
y.selectedIndex = 0;
}
}
call this javascript on the admission_class field .

No comments:

Post a Comment