Page 1 of 1

Radio button if statements

Posted: 16 Feb 2018
by Roo
I've read quite a few comments on the forums here about radio button control (and have also visited the control site https://spform.com/javascript-framework ... eld-values)

However I'm struggling work out how to check the value of the radio button label.

I have a radio control (internal name 'IssueType') with 7 choices
Audit
Environment
internal etc etc

If I want to control other elements of the form from what has been choosen I used this:

function showHideFields(){
if (fd.field('IssueType').value() == 'Audit') {
$('.TAbleAudit').show();
}
else {
$('.TAbleAudit').hide();
}
}

//call the function on opening
showHideFields();

However, it doesn't work - Do I have to store the value as a variable and then use the variable within the if statement?

Re: Radio button if statements

Posted: 16 Feb 2018
by Roo
I've got around this by using the index number (I had previous tried this, but without the "") so the code is as follows if it helps anyone:

function showHideFields(){
if (fd.field('IssueType').value() == "1") {
$('.TAbleAudit').show();
}
else{
$('.TAbleAudit').hide();
}
}


//call the function on opening
showHideFields();

Re: Radio button if statements

Posted: 16 Feb 2018
by Nikita Kurguzov
Dear Roo,
Good job! I didn't even have time to answer the question, but yes, you are correct, by default Radio button choice returns number of the choice, instead of text. To get the text, you can use the following code, even though it's a bit lengthy:

Code: Select all

var issueTypeNum = fd.field('IssueType').value();
if (fd.field('IssueType').control()._el().find('td').eq(issueTypeNum).find('label').text()  == 'Audit'){
}