File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes html:radio Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "html:radio " Watch "html:radio " New topic
Author

html:radio

Muhammad Imad Qureshi
Ranch Hand

Joined: Sep 13, 2005
Posts: 238
Hi I want to use the value of selected radio button in one function. how do I get the value because document.getElementById('...') dont seem to work. it always returns the value of first radio button even if second is selected.
Here is what I am doing

<html:radio name="fodMaintenanceForm" property="fax.isPublic" value="1" styleClass="privacyOptions" /><bean:message key="app.public" />
<html:radio name="fodMaintenanceForm" property="fax.isPublic" value="0" styleClass="privacyOptions" /><bean:message key="app.group" /> 

and then trying to use the value in the folowing code

(document.getElementById('privacyOption').value);

but it always returns the first value that is 1.
Muhammad Imad Qureshi
Ranch Hand

Joined: Sep 13, 2005
Posts: 238
Can someone please help me with this.
Thanks
Chris Baron
Ranch Hand

Joined: Mar 21, 2003
Posts: 1049
Hi Muhammad,
you've got to iterate over the radios and find the checked one.



call the function with the radios' groupname
findSelectedRadioButton('privacyOptions')

HTH cb
Muhammad Imad Qureshi
Ranch Hand

Joined: Sep 13, 2005
Posts: 238
Hi Thanks for your reply
But what will be my group name. because I cannot use style class. am i suppose to use property as the group name. because name itself cannot be a group name because it is my form name which has everything configured in struts-config.xml including the property fax (java class Fax) which has one property isPublic.

Thanks a lot
Chris Baron
Ranch Hand

Joined: Mar 21, 2003
Posts: 1049
Ooops,
What is name of the radios, if you open the html-pagesource in the browser?
cb
[ October 19, 2005: Message edited by: Chris Baron ]
Muhammad Imad Qureshi
Ranch Hand

Joined: Sep 13, 2005
Posts: 238
Hi chris this is the code in the browser

<input type="radio" name="fax.isPublic" value="1" class="privacyOptions">Public

<input type="radio" name="fax.isPublic" value="0" checked="checked" class="privacyOptions">Group 

now probably because of this "." in fax.isPublic i m getting this error.

i always get fax property is not defined.
i m waiting for your reply
thanks for your help.
Chris Baron
Ranch Hand

Joined: Mar 21, 2003
Posts: 1049
No,
it's not the dot. I just tried and it works.
Did you replace "myform" with the form's name you found in the html-pagesource?


cb
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Moved to the HTML/Javascript forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Muhammad Imad Qureshi
Ranch Hand

Joined: Sep 13, 2005
Posts: 238
Chris Thank you so much I really appreciate your help.

This how I did it. It was more simple than I thought.

simple give styleId(a different styleId for each button) to each radio button.

and then use

document.getElementById('public').checked
and if this returns true then set the value.

following is the code I used. I hope it helps someone like me in future

<html:radio name="fodMaintenanceForm" property="fax.isPublic" value="1" styleClass="privacyOptions" styleId="public"/><bean:message key="app.public" />

<html:radio name="fodMaintenanceForm" property="fax.isPublic" value="0" styleClass="privacyOptions" styleId="group"/><bean:message key="app.group" /> 

and then use in my javascript vode as follows

if (document.getElementById('public').checked)
{
document.fodCreatorApplet.setIsPublic(document.getElementById('public').value);
}

else if (document.getElementById('group').checked )
{
document.fodCreatorApplet.setIsPublic(document.getElementById('group').value);
}

thanks again.
 
wood burning stoves
 
subject: html:radio
 
Similar Threads
Radio control in Struts
html:radio..
How to make dynamic radio button checked
problem with "html:radio"
accessing radio button in Javascript