0

I need to check if 3 fields have been filled in on a form. I am using the following code - instead of click event I am using mouseover, otherwise it will reload the page: I followed the suggestions from this page

$('#dnn_ctr503_DynamicForms_lnkSave').on('mouseover',function()
{
    if( $('#dnn_ctr503_DynamicForms_TBR_GUID35b841a2-5019-4cb0-9041-1204c90e5bebEmail').val().length === 0 ) {
        alert('warning');
    }
});

How could I insert 2 more fields in the code please. So if any of these 3 fields are not filled in the warning message will show up. Thank you.

Community
  • 1
  • 1

2 Answers2

0

Add the other two validation similarly. Just add return after the alert.

Vijendra Kumar Kulhade
  • 2,217
  • 3
  • 15
  • 25
  • Would it be like this: `$('#dnn_ctr503_DynamicForms_lnkSave').on('mouseover',function() { if( $('#dnn_ctr503_DynamicForms_TBR_GUID35b841a2-5019-4cb0-9041-1204c90e5bebEmail').val().length === 0 ) { alert('warning'); } return }); ` – Reka Salamon Jun 23 '16 at 14:59
  • oh so you want to keep the validation code common for all three input fields? If yes then instead of id give class like `$('.dnn_DynamicForms_lnkSave_class').on('mouseover'` and same kind of check will work for all 3 fields. – Vijendra Kumar Kulhade Jun 23 '16 at 23:06
0

The problem is that I haven`t got access to the source files, so I can not add 'required'. I will need to extend my code somehow with comas or adding extra code. I have tried the following:

$('#dnn_ctr503_DynamicForms_lnkSave').on('mouseover',function()
{
    if( $('#dnn_ctr503_DynamicForms_TBR_GUID35b841a2-5019-4cb0-9041-1204c90e5bebEmail, #dnn_ctr503_DynamicForms_TBR_GUIDaa4a3017-b28d-46d2-ae6e-7d56b2b886c5Name, #dnn_ctr503_DynamicForms_TBR_GUIDfb4cb1b0-30b9-475f-bb92-7c3d35275e55Message').val().length === 0 ) {
        alert('Please fill in all required fields(*)!');
    }
});`

But it doesn`t seem to be working with 3 fields in this way.

  • `$('#button_lnkSave').on('mouseover',function() { if( $('#Name').val().length === 0 ) { alert('Please fill in all required fields(*)!'); } if( $('#Email').val().length === 0 ) { alert('Please fill in all required fields(*)!'); } if( $('#').val().length === 0 ) { alert('Please fill in all required fields(*)!'); } });` – Reka Salamon Jun 24 '16 at 12:51
  • I am having 3 if conditions at the moment, but I would like it to be one condition to check if any of these 3 fields are empty and show the alert message only once, at the moment it pops up 3 times – Reka Salamon Jun 24 '16 at 12:54