Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

html:radio

 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please help me with this.
Thanks
 
Chris Baron
Ranch Hand
Posts: 1061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the HTML/Javascript forum.
 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic