Struts and Radio button problem

I have  a struts  question.



Objective:
==========

a) I need  to  have 3  radio button.

b) when you select any radio,others should be unselected  i.e only one radio button can be chosen at any point of time

c) onchange of any radio button i want to submit the form.

d) Initially,the first radio  button would be selected.






Problem  I Faced
=================



i am in trouble to maintain  these things with radios.....

procedure 1
============

if i use

<html:radio  property="radiobutton" value="abc">
<html:radio  property="radiobutton" value="def">
<html:radio  property="radiobutton" value="ijk">


I cant submit the form onchange of radios......reason is, if i choose second radio  javascript would prompt "undfined" becoz it wont dstinguish the different radios




procedure 2
============

if i use

<html:radio  property="radiobutton1" value="abc">
<html:radio  property="radiobutton2" value="def">
<html:radio  property="radiobutton3" value="ijk">


thoug javascript would allow submit  form onchange of radios but i cant uncheck other radios upon selection of another radios.





Question To you guys
====================

can you tell me the solution of my objective ?
dont think about my approaches/procedures because those were trials which was fruitless. I think, there must be some standard way to solve this kind of problem.

how to solve this problem ?

thank you








cofactorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cofactorAuthor Commented:
i forgot to add  'onchange'  on each radios...but it is there.
radarshCommented:
What type is your variable in ActionForm?

________
radarsh
radarshCommented:
First of all, a radio button is used to select only one value.
So, you must follow the procedure 1 in which you have the same property defined for all three buttons.

Now, how are you trying to submit using JavaScript?
It should be onchange="document.FormName.submit();"
Why do you need to distinguish the radios?

All the three radio buttons together represent one input.

Take an example of gender. It can be M or F. And we can provide two radio buttons for that.
each with property equal to gender. Values will be M and F. Now, what gets submitted is
actually gender=M or gender=F.

I guess yours is a similar scenario. Can't you distinguish the value at the server side?

Correct me if I have gotten your question wrong.


________
radarsh
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

radarshCommented:
Your form control (ActionForm variable) should be a String

________
radarsh
cofactorAuthor Commented:
feedback
======
>What type is your variable in ActionForm?

i have DynaActionForm and all  properties are 'String".

>Why do you need to distinguish the radios?

I need it.....because i am sending the value NOT to Action but to  a sinple JAVA class. I am using AJAX(DWR).

Anyway,  i need the value of the radio the user has chosen. once i  get  the value of the radio and i submit this

<script>
function submitMe()
{

var val=document.forms[0]radio.value // this prompts error

MyjavaClass.getValue(val)

// blah blah


}
</script>

and i call the above function from the onchange of radio

As  i told  '//this prompts error", because javascript cant extract the  value !  because all  the radio have same name and so JS has got confused and so it throws "undefined error"

I am stuck here.


N.B:  sorrry, to use the word "submit' the form.....actually it is not the "submit"  but calling the java  classs onchange of radio button as above.


But the problem is JS is not allowing to extract the radio value

How to come around it ?
radarshCommented:
I guess you have problems with your JS

It should be:

function submitMe()
{

var val=document.forms[0].radiobutton.value
MyjavaClass.getValue(val)

// blah blah


}


radiobutton is the name of the property attribute of <html:radio...>

Well, what are you trying to do by MyjavaClass.getValue(val)?
Are you trying to invoke Java code from JavaScript?

Remember Java code is server side code. And JavaScript is client side. You just can't do that
if that's what you are trying to do.

________
radarsh
cofactorAuthor Commented:
again that was a silly mistake .

yes you are right
var val=document.forms[0].radiobutton.value

its my spell mistake.

sorry


>Remember Java code is server side code. And JavaScript is client side. You just can't do that
>if that's what you are trying to do.

 i do it always  :-)   ....... i enjoy it . had it not been a radio , i would have become lucky.
anyway, i changed this radio to a select box and now this works fine.

However, i could not solve it using radio.

 you can call a java class from Javascript , please have a look here

http://getahead.ltd.uk/dwr/documentation

I am using this.
radarshCommented:
That's cool!! I'm new to AJAX. Well, thanks for the link :)

Probably this is one instance where the Answerer has benefited more than the Questioner ;)

________
radarsh
GranModCommented:
PAQed with points refunded (50)

GranMod
Community Support Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.