Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Javascript get value from Radio Button

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED] Javascript get value from Radio Button
 Login/Join
 
Guru
posted
Hi,

I have a radio button group on my html page that has three values. I'm trying to retrieve the value of the selected option using the code below but it doesn't work.
//Begin function radio1_onclick
function radio1_onclick(ctrl) {
var radBut = document.getElementById('radio1');
for (var i=0; i < radBut.length; i++)
   {
   if (radBut[i].checked == true)
      {
      alert(radBut[i].value);
      }
   }
}
//End function radio1_onclick


I get nothing. Not even a script error. Am I missing something?

Thanks,

Dan

This message has been edited. Last edited by: Dan Pinault,


7.7.05M/7.7.03 HF6 on Windows Server 2003 SP2 output to whatever is required.
 
Posts: 393 | Location: St. Paul, MN | Registered: November 06, 2007Report This Post
Platinum Member
posted Hide Post
Dan,

Here is some old code of mine that I think will get you going. The thing is to treat a radio group as an array.

     for (var i = 0; i < 3; i++) {
       if (document.formname.radioname[i].checked == true ){
	SelectedValue += document.formname.radioname[i].value ; 
	}
	}
 

This message has been edited. Last edited by: Dave Ayers,


Regards,
Dave

http://www.daveayers.com

WebFocus/Maintain 7.6.4-8
on Win2000 and 2003 Server
 
Posts: 165 | Location: Detroit Metro | Registered: September 17, 2003Report This Post
Gold member
posted Hide Post
Dan,
I got this working....perfectly...
 

 var radBut=document.form_name.radio1.length;
 alert(radBut);
 for (var i=0; i < radBut; i++)
 {
 if (document.form_name.radio1[i].checked==true)
    alert(document.form_name.radio1[i].value);
 }
}


please make sure to give the unique id for all the radio buttons as "radio1".......this may be the problem in your case.......
let us know if you got it working........
Smiler
regards,
Anmol.


WebFocus7.6.2, WebFocus 7.1.1,Windows
HTML, PDF and Excel
 
Posts: 71 | Registered: June 30, 2009Report This Post
Guru
posted Hide Post
Thanks for the responses Dave and Anmol.

I don't know if it makes a difference or not but I'm using the radio button control from the html layout composer. It looks like this is behaving differently than a 'normal' radio button control.

My three options look like this...
<TR>
   <TD>
   <LABEL id=radio1_LABEL_0 style="CURSOR: default" for=radio1_0>
   <INPUT id=radio1_0 tabIndex=22 type=radio CHECKED value=SUM name=radio1 displaytext="Summary">Summary</LABEL></TD>
   <TD>
   <LABEL id=radio1_LABEL_1 style="CURSOR: default" for=radio1_1>
   <INPUT id=radio1_1 tabIndex=22 type=radio value=PRINT name=radio1 displaytext="Detail">Detail</LABEL></TD>
   <TD>
   <LABEL id=radio1_LABEL_2 style="CURSOR: default" for=radio1_2>
<INPUT id=radio1_2 tabIndex=22 type=radio value=COUNT name=radio1 displaytext="Count">Count</LABEL></TD></TR>


This looks to me like they are behaving like checkboxes. So, the code I ended up with is...
//Begin function radio1_onclick
function radio1_onclick(ctrl) {
if (document.getElementById('radio1_2').checked==true)
    {
    //Do this if true
    }
else
    {
    //Do this if false
    }
}
//End function radio1_onclick


The reason I am looking to see if the particular radio button (radio1_2) is checked is so I can [enable] or [uncheck and disable] a checkbox (checkbox8). The strange thing is that I need to reference the actual checkbox of checkbox8 as 'item1'! Go figure!!
//Begin function radio1_onclick
function radio1_onclick(ctrl) {
var chkBox = document.getElementById('checkbox8');
if (document.getElementById('radio1_2').checked==true)
	{
    chkBox.disabled=false;
	}
else
	{
	document.getElementById('item1').checked=false; 
	chkBox.disabled=true; 
	}
}
//End function radio1_onclick



Thanks for the help!

Dan


7.7.05M/7.7.03 HF6 on Windows Server 2003 SP2 output to whatever is required.
 
Posts: 393 | Location: St. Paul, MN | Registered: November 06, 2007Report This Post
Platinum Member
posted Hide Post
Dan,

Notice that while the IBI generated code has different "id=" values, the "name=" value is the same, 'radio1', for all the radio button elements, so you can use that to refer to the collection properties by name, not Id.


Regards,
Dave

http://www.daveayers.com

WebFocus/Maintain 7.6.4-8
on Win2000 and 2003 Server
 
Posts: 165 | Location: Detroit Metro | Registered: September 17, 2003Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Javascript get value from Radio Button

Copyright © 1996-2020 Information Builders