show/hide on Client Script

huyjor
Tera Contributor

Hello Everyone 

I'm trying to create registration form. When the user selects student, it should show the student registration form. When the user selects instructor, it should show instructor registration form. I'm getting an error "onChange script error: ReferenceError: student is not defined function () { [native code] }". Not sure why if i miss anything. Or anything wrong with my script. Thanks for you help. 

 

I wrote the client script on change:

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    /*
    var selection = g_form.getSectionNames();
  The alert comes back to me as student_registrationform
alert(selection);
*/
    if (g_form.getValue('student_or_instructor') == student) {
        g_form.setSectionDisplay('student_registrationform', true);
    } else {
        g_form.setSectionDisplay('student_registrationform', false);
    }
}
3 ACCEPTED SOLUTIONS

Danish Bhairag2
Tera Sage
Tera Sage

Hi @huyjor ,

 

In this line 

 

if (g_form.getValue('student_or_instructor') == student) {

 

Student should be under double/single qoutes else it will treat it as a variable.

 

Do something like this

 

if (g_form.getValue('student_or_instructor') == "student") {

 

It should work.

 

Thanks,

Danish

 

View solution in original post

Sandeep Rajput
Tera Patron
Tera Patron

@huyjor Please update your script as follows.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    /*
    var selection = g_form.getSectionNames();
  The alert comes back to me as student_registrationform
alert(selection);
*/
    if (g_form.getValue('student_or_instructor') == 'student') {
        g_form.setSectionDisplay('student_registrationform', true);
    } else {
        g_form.setSectionDisplay('student_registrationform', false);
    }
}

 

Hope this helps.

View solution in original post

Musab Rasheed
Tera Sage
Tera Sage

No need to use getValue , you can use newValue like below.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    /*
    var selection = g_form.getSectionNames();
  The alert comes back to me as student_registrationform
alert(selection);
*/
    if (newValue == 'student') {
        g_form.setSectionDisplay('student_registrationform', true);
    } else {
        g_form.setSectionDisplay('student_registrationform', false);
    }
}
Please hit like and mark my response as correct if that helps
Regards,
Musab

View solution in original post

6 REPLIES 6

SLK Gupta
Tera Guru

Hi @huyjor ,

 

If selecting student or instructor is it a choice field, if it is a choice field you can use a UI policy & UI Policy action @huyjor . without writing scripting you can fulfill the requirement @huyjor .

 

Let me know, how it works for you.

 

If my answer helps you in anyway please mark it as accepted solution or helpful @huyjor .

 

Thanks & Regards,

S. Lakshmikanth Gupta.

Danish Bhairag2
Tera Sage
Tera Sage

Hi @huyjor ,

 

In this line 

 

if (g_form.getValue('student_or_instructor') == student) {

 

Student should be under double/single qoutes else it will treat it as a variable.

 

Do something like this

 

if (g_form.getValue('student_or_instructor') == "student") {

 

It should work.

 

Thanks,

Danish

 

Sandeep Rajput
Tera Patron
Tera Patron

@huyjor Please update your script as follows.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    /*
    var selection = g_form.getSectionNames();
  The alert comes back to me as student_registrationform
alert(selection);
*/
    if (g_form.getValue('student_or_instructor') == 'student') {
        g_form.setSectionDisplay('student_registrationform', true);
    } else {
        g_form.setSectionDisplay('student_registrationform', false);
    }
}

 

Hope this helps.

Musab Rasheed
Tera Sage
Tera Sage

No need to use getValue , you can use newValue like below.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    /*
    var selection = g_form.getSectionNames();
  The alert comes back to me as student_registrationform
alert(selection);
*/
    if (newValue == 'student') {
        g_form.setSectionDisplay('student_registrationform', true);
    } else {
        g_form.setSectionDisplay('student_registrationform', false);
    }
}
Please hit like and mark my response as correct if that helps
Regards,
Musab