Search code examples
javascriptfacebookfbjs

Form Validation with FBJS


I've a form validation problem with FBJS to use on Facebook application. I checked out validation examples on documentation and I can check textbox values with form.serialize(); but unfortunetely I couldn't figure out how to check dropdown and checkbox values.

Thanks in advance..


Solution

  • For check boxes and radio buttons use code like this:

    if (document.getElementById("checkbox_or_radio_button_id_here").getChecked() == true)
    {
        // yes it was checked
    }
    

    For dropdown:

    if (document.getElementById("dropdown_id_here").getValue() != '')
    {
        // yes dropdown was not empty
    }
    

    I personally don't use serialize in facebook validation, i just use simple code as above.

    Thanks, hope that helps.