cancel
Showing results for 
Search instead for 
Did you mean: 

radio button selection check using java script in BSP page

Former Member
0 Kudos

Hi,

We have requirement where we have to show alert popup if there is no radio button selected. For this we are getting selected radio button in ABAP code in oninput processing, but we have to detect the same in java script code in layout.

Any input regarding this will be grate help.

Thanks & regards,

Rahul.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Try this in <script> tag :

function checkRadio(formname, radioname, displaytext) {

var localerror = '';

var rad_val = '';

for (var i=0; i < eval('document.'formname'.'radioname'.length'); i++) { //check every radio button by that name

if (eval('document.'formname'.'radioname'<i>.checked')) { //if it is checked

rad_val += '-';

} else rad_val += '';

}

if (rad_val=='') {

localerror = '- 'displaytext' is Required.\n';

}

if (rad_val=='') { return ;}

else

{

alert( localerror );

}

}

Call this function in clientClick event of button using:

checkRadio(formname, radioname, displaytext);

Hope it helps,

Pragya

eddy_declercq
Active Contributor
0 Kudos

Hi,

Pls don't forget to reward points and close the question if you find the answers useful.

Eddy

athavanraja
Active Contributor
0 Kudos

document.getElementbyId(<radiobuttonid>).value will return the value of the radiobutton

Regards

Raja

eddy_declercq
Active Contributor
0 Kudos

Hi,

Checking if a radio button is checked, can be done via this code

get the buttons with that name

var aFormField = document.forms[0].elements[aName];

loop for the number of buttons

for (i=0;i<aFormField.length;i++){

if it is checked

if(aFormField<i>.checked){

dosomething

break;

}

}

If it is only one button, document.forms[0].elements[aName].checked can be sufficiant.

Eddy

Eddy