function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RAJU_DEEPRAJU_DEEP 

onclick() not working properly

Hello,

            I am in a problem which seems to be silly but any how i stucked to it. I have a javascript code

 

function saveRecord()
        {
          if (document.getElementById("{!$Component.pg.frm.in}").value > document.getElementById("{!$Component.pg.frm.out}").value)
              {
              alert('SignIn time should be less then SignOut time');
              }
            else if (document.getElementById("!$Component.pg.frm.in").value != '')
              {
              alert("Record Saved Successfully...");
              }
            else
              {
              alert("Enter the SignIn Time");
              }
       }

          In this function the two datetime inputFields values is been used for the validation purpose.

 

this function is called by the command button through onclick, when i click on the button asper the condition it displays the first alert but if the condition switches to the nested if-else it doesn't shows anything. I don't know where i am going wrong. Is there any way to solve this.

 

Thanks in advance.

Raju.

 

Best Answer chosen by Admin (Salesforce Developers) 
RAJU_DEEPRAJU_DEEP

Hello,

           Thanks for your reply but I got the solution with the empty string.

 

function saveRecord()
        {
            if(document.getElementById("{!$Component.pg.frm.out}").value == '')
            {
                alert('SignIn Time Logged Successfully...');
            }
            else if(document.getElementById("{!$Component.pg.frm.in}").value > document.getElementById("{!$Component.pg.frm.out}").value)
            {
                alert('SignIn time should be less then SignOut time');
            }
            else
            {
                alert("SignOut Time Logged Successfully...");
            }
        }

 

 

All Answers

Pradeep_NavatarPradeep_Navatar

In nested if-else, don't use empty string. You should use null instead. Modify the code and run again. It should work.

 

Hope this helps.

 

RAJU_DEEPRAJU_DEEP

Hello,

           Thanks for your reply but I got the solution with the empty string.

 

function saveRecord()
        {
            if(document.getElementById("{!$Component.pg.frm.out}").value == '')
            {
                alert('SignIn Time Logged Successfully...');
            }
            else if(document.getElementById("{!$Component.pg.frm.in}").value > document.getElementById("{!$Component.pg.frm.out}").value)
            {
                alert('SignIn time should be less then SignOut time');
            }
            else
            {
                alert("SignOut Time Logged Successfully...");
            }
        }

 

 

This was selected as the best answer