SharePoint 2010 - JavaScript - Make a field required and add a red asterisk

Question

ran009 on Sat, 19 Jan 2013 01:02:21


Hi I use SharePoint 2010 (can use JQuery and SP Query).

On checkbox select 
{
 Make a date field required 
  and 
 add a red asterisk next to it
}

Code will be really appreciated.

Thanks folks.





Replies

Hemendra Agrawal on Sat, 19 Jan 2013 04:58:33


Hi,

Here is similar thread to make field mandatory using jquery:

http://stackoverflow.com/questions/6573487/jquery-validation-select-required-if-checkbox-checked

Second way, you can edit your page (if you want this on list forms) in infopath designer and add data validation rule on field to make it mandatory based on chkbox selection.

Can you please let us know where you want this?

AliYasir on Sun, 20 Jan 2013 04:03:21


Hi, 

Dear Indul, request you to do not self propose your answer as correct.

Hi ran009,

You can create a lable and initially keep is display = none.

On javascript, check it $('#controlid').text() == ''

then mark the label display property to block and return false.

$(document).ready(function(){

$('#btn').click(function(){

if($('#controlid').text == '')
{
$('#astrik').attr('style','display:block');
}
return false;
});
return true
});