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.

New TIBCO Community Coming Soon
In early summer, TIBCO plans to launch a new community—with a new user experience, enhanced search, and expanded capabilities for member engagement with answers and discussions! In advance of that, the current myibi community will be retired on April 30. We will continue to provide updates here on both the retirement of myibi and the new community launch.

What You Need to Know about Our New Community
We value the wealth of knowledge and engagement shared by community members and hope the new community will continue cultivating networking, knowledge sharing, and discussion.

During the transition period, from April 20th until the new community is launched this summer, myibi users should access the TIBCO WebFOCUS page to engage.


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