How to show popup message using Jquery when nothing is selected from Choice field in Newform.aspx page of list?

Hi All,

I have a "Choice" field . the choice field type is Checkbox type with multi selection in "Newform.aspx" page of list.

I want to show a popup message when value is not selected from Choice field using jquery.

for example:- Choice field name is "Select Country"

                                       Value are     1. Australia

                                                               2. India

                                                               3. UK

if nothing is selected and click Save button in newform of list then it should show pouup mesage "Please select at least one"; 

Note- using Jquery.

Thanks,


June 17th, 2015 9:27am

Actually I tried this but did not work for me:-

function PreSaveAction()   
   {
     if($("select[title='Select Country'] option:selected").val() == '')
     {
        alert("Please select.")
        return false;
     }
    else
    {
    return true;
    }

  }

Free Windows Admin Tool Kit Click here and download it now
June 17th, 2015 9:29am

Hi,

The val property is not the right one to check. You can either check selectedIndex like this:

function PreSaveAction()   
   {
     if($("select[title='Select Country']").selectedIndex == -1)
     {
        alert("Please select.")
        return false;
     }
    else
    {
    return true;
    }

  }

Or you can check the length of selected values like this:

function PreSaveAction()   
   {
     if($("select[title='Select Country'] option:selected").length == 0)
     {
        alert("Please select.")
        return false;
     }
    else
    {
    return true;
    }

  }

June 17th, 2015 1:42pm

Hi,

Is 'Minimal Download Strategy' web feature activated on your site? Can you deactivate this feature and try your code block in CEWP on editform.aspx of your list?

<script src="/Style%20Library/jquery.min.js"></script> 
<script type="text/javascript">
function PreSaveAction()   
   {
    if($("select[title='Select Country'] option:selected").val() == '')
    {
        alert("Please select.")
        return false;
    }
    else
    {
    return true;
    }
  }
</script>

Thanks, Please mark it as an answer if it helps.

Free Windows Admin Tool Kit Click here and download it now
June 17th, 2015 1:58pm

Hi Robi ,

Even I am selecting checkbox and saving then its showing alert message.

I meant to say, always selected length is 0 even I am selecting the checkbox.

Thanks for your post.

Note - Field is Choice Filed NOT dropdown.
June 18th, 2015 2:02am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics