cancel
Showing results for 
Search instead for 
Did you mean: 

Getting value from HTMLB radiobutton error...

Former Member
0 Kudos

Hi, I am getting an Javascript error saying <b>"selectedRadioValue has no properties"</b> with the following code. When the user clicks the a radio button, there is an alert displaying the selected radio button text. I was wondering if anyone can see what is wrong in my short code below?

Thanks so much, Baggett

<b><%@ taglib uri="tagLib" prefix="hbj" %>

<SCRIPT LANGUAGE="JavaScript" TYPE="text/JavaScript">

function alertSelectedRadio(){

var funcName = htmlb_formid+"_getHtmlbElementId";

func = window[funcName];

var selectedRadioValue = eval(func(htmlb_radiobuttonmodifier+"TestRadioButton"));

var radiotext = selectedRadioValue.getText();

alert("*** The radio button you selected is = " + radiotext);

} </SCRIPT>

<hbj:content id="myContext" >

<hbj:page title="Initial Page">

<hbj:form id="myFormId">

<hbj:gridLayout width="50%" >

<hbj:gridLayoutCell rowIndex="1" columnIndex="1" style="">

<hbj:radioButtonGroup id="TestRadioGroup" columnCount="2" selection="rb_fem">

<hbj:radioButton id="TestRadioButton" text="female" key="rb_fem" tooltip="I am female" jsObjectNeeded="TRUE" disabled="false" />

<hbj:radioButton id="TestRadioButton" text="male" key="rb_male" tooltip="I am male" jsObjectNeeded="TRUE" disabled="false" />

</hbj:radioButtonGroup>

</hbj:gridLayoutCell>

<hbj:gridLayoutCell rowIndex="1" columnIndex="2" style="">

<hbj:button id="button1" text="Get Radio Button Pressed" jsObjectNeeded="TRUE" onClientClick="alertSelectedRadio()" />

</hbj:gridLayoutCell>

</hbj:gridLayout>

</hbj:form>

</hbj:page>

</hbj:content></b>

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Baggett,

I found out there is a bug with SAP's code. The only way to get hold of radio button is by using the following code.

function alertSelectedRadio(){
var funcName = htmlb_formid+"_getHtmlbElementId";
func = window[funcName];
//you have to specify the group name
var selectedRadioValue1 = eval(func("TestRadioGroup" + htmlb_radiobuttonmodifier.substring(3,7)+ "1"));
var selectedRadioValue2 = eval(func("TestRadioGroup" + htmlb_radiobuttonmodifier.substring(3,7)+ "2"));
alert(selectedRadioValue1.getValue());
alert(selectedRadioValue1.getChecked());
alert(selectedRadioValue2.getValue());
alert(selectedRadioValue2.getChecked());

}

Message was edited by: Prakash Singh

Former Member
0 Kudos

Hi Prakash, thanks for your response! It now works on my machine!

<b>1.)</b> Do you know a website that talks about SAP HTMB with Javascript interaction?

<b>2.)</b> Also, the bug here was that the line:

<b>var selectedRadioValue = eval(func(htmlb_radiobuttonmodifier+"TestRadioButton"));</b>is suppose to work?

Thanks so much again Prakash!

Baggett

Former Member
0 Kudos

1. I have learned mainly from PDK. I will tell you a trick. Open your iView in a new window via IE and click on "save as" to save all the content. The IE automatically saves all the content ( javascript, css .. etc in a folder) and what you will find is controls_ie5.js file which has all the javascript code that portal uses for htmlb control.

2. That line is suppose to work according to PDK but it doesn't.

Later

prakash

Former Member
0 Kudos

Hi Prakash, thanks for your valuable trick and thanks again for your help in solving this problem!

Thanks again!

Baggett.

Answers (1)

Answers (1)

Former Member
0 Kudos

to check which radio is checked you use the following property.

selectedRadioValue.isChecked() 

<b>Note: Your code has same id for both the radio buttons. They should have different id.</b>

Former Member
0 Kudos

Hi Prakash, thank you so much for your response.

<b>1.</b> Is this the correct way to use .isChecked()?

<b>var selectedRadioValue = eval(func(htmlb_radiobuttonmodifier+"TestRadioButton"));

var radiotext = selectedRadioValue.isChecked().getText();</b>

<b>2.</b> If I use the same id for both radio buttons, then what parameter would I use inside the eval(func()) if I wanted to find out which radio the user clicked, i.e:

<b>var selectedRadioValue = eval(func( ? ));</b>

Would I have to do a conditional loop to go through all the radio boxes?

Thanks so much,

Baggett.

Former Member
0 Kudos

1. To get the text your original code is fine. I think it's probably not working because your radio button have the same id.

<b>var selectedRadioValue = eval(func(htmlb_radiobuttonmodifier+"TestRadioButton"));

var radiotext = selectedRadioValue.getText();</b>

2. You can't use the same id for both the radio buttons. and you will have to write a conditional statement to check the value of each radio button.

Example:

if ( selectedRadioValue1.isChecked()){
              }
           else if (selectedRadioValue2.isChecked() {
             }

Former Member
0 Kudos

Hi Prakash, thank you for your response. After changing code, I am getting <b>"selectedRadioValue1 has no properties"</b>. I'm wondering if you see anything wrong w/ my code, I've pasted my js code and part of radio html code.

Thanks so much Prakash! Baggett.

<b>function alertSelectedRadio(){

var funcName = htmlb_formid+"_getHtmlbElementId";

func = window[funcName];

var selectedRadioValue1 = eval(func(htmlb_radiobuttonmodifier+"TestRadioButton1"));

var selectedRadioValue2 = eval(func(htmlb_radiobuttonmodifier+"TestRadioButton2"));

if ( selectedRadioValue1.isChecked()){

var radiotext1 = selectedRadioValue1.getText();

alert("1");

}

else if (selectedRadioValue2.isChecked()) {

var radiotext2 = selectedRadioValue2.getText();

alert("2");

}

} </b>

and my 2 radio buttons:

<b><hbj:radioButton id="TestRadioButton1" text="female"

key="rb_fem" tooltip="female" jsObjectNeeded="TRUE" disabled="false" />

<hbj:radioButton id="TestRadioButton2" text="male" key="rb_male" tooltip="male" jsObjectNeeded="TRUE"

disabled="false" /></b>

Former Member
0 Kudos

Hi Baggett,

can you tell me what line is giving you javascript error.

Former Member
0 Kudos

Hi Prakash, thank you for your response. The error is happening inside the conditional "if" statement, where I try to access the selectRadioValue1 object:

<b>if ( selectedRadioValue1.isChecked()){

var radiotext1 = selectedRadioValue1.getText();</b>

I then get the <b>"selectedRadioValue1 has no properties"</b> error message. Somehow maybe I am not creating my radio group right?

Prakash, would you like me to paste my entire code? It is pretty short.

Thanks so much,

Baggett.