aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Radio Buttons Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Radio Buttons" Watch "Radio Buttons" New topic
Author

Radio Buttons

John Lark
Ranch Hand

Joined: Feb 08, 2010
Posts: 72
Hey all,

I am having some dififculty with radio buttons. I have inserted them into my JSP page via java script.

<input type = "radio" poperty ="a" value = "b">

<input type = "radio" poperty ="a" value = "c">

When I submit them they are read in the action(using struts) and used to set certain boolens to true or false depending on which radio button is selected, this is done for sort of a permissions page. However, when I load the page all the radio buttons are unchecked. I would like to have them set to the ones previously selected. I could insert if statments to do this but trying to do it right not simply do it. I would also perfer to stay with the javascript as I will be moving away from the struts methodology.

Anyone have any ideas?

Thanks
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

If you're inserting them via JavaScript, then you'll need to track which value is selected via JavaScript as well.
John Lark
Ranch Hand

Joined: Feb 08, 2010
Posts: 72
So then somthing along the lines of inserting a js file and then preforming a radio button like

<input type = "radio" Name = "a" Value = "b" Checked = isChecked()>
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Well, I'm not sure what that "isChecked()" bit is, but yes.
John Lark
Ranch Hand

Joined: Feb 08, 2010
Posts: 72
The ischecked bit would just a potential java function name connected to the js file I would use to figure out whats what.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You can't call Java from a JavaScript file: Java is executed on the server; JavaScript is executed on the client (browser) after *all* the Java classes have been run and the JSP has been rendered.
John Lark
Ranch Hand

Joined: Feb 08, 2010
Posts: 72
Thats dumb you can do it in ASP!? Okay ill take your word for it I think im just going to try moving towards <html:radio> anyway ty for the help!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Well, you might be a little confused about how ASP works, unless you're talking about the Ajax extensions. Which could be duplicated.

It's not clear to me at all why you're building the radio buttons in JavaScript in the first place, though. You won't be able to build <html:radio> buttons in JavaScript, btw, for the same reason. You can mimic their rendered HTML, but you'll still have to set the value in JavaScript.

Maybe if you were a bit more descriptive in what you're trying to do this would be an easier discussion.
John Lark
Ranch Hand

Joined: Feb 08, 2010
Posts: 72
Its a JSP page ! Perhpas I just dont know what im doing lol which is probably most likley *shrugs* got to start somewhere.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

ASP doesn't let you do anything on client that's "magic" any more than JSP does.

Like David, I really have no idea what you are actually trying to accomplish. Maybe it'd be best to step back a bit and explain that.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
John Lark
Ranch Hand

Joined: Feb 08, 2010
Posts: 72
Obviously its not "magic" there is no need to be insulting because I dont understand, at one time you didnt. I have inserted .js files into my header before, and used them to hide forms when certain files are selected, and also use them for validation which is understandably different. But surely you could see how that could be confusing?

Thanks,
John Lark
Ranch Hand

Joined: Feb 08, 2010
Posts: 72
O for stepping back I probably have partially failed to explain correctly.

what I called Javascript where lines of code I inserted into my JSP page, which isnt java script when you think about it I just interpreted it as such. I think I need to look at it myself some more thanks for trying though guys!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

John Lark wrote:Obviously its not "magic" there is no need to be insulting because I dont understand, at one time you didnt.
If you found my post insulting, then you need to turn the gain on your Offense-o-Meter way down. We're trying to help you here. No insult is intended.

Sometimes people get too close to the problem, which is why you are being asked to step back a bit and explain the goals rather than the tactics.


John Lark
Ranch Hand

Joined: Feb 08, 2010
Posts: 72
lol your right sry!
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
John Lark wrote:The ischecked bit would just a potential java function name connected to the js file I would use to figure out whats what.


Shouldn;t it say potential javaScript function

Java != JavaScript

eric
John Lark
Ranch Hand

Joined: Feb 08, 2010
Posts: 72
Okay I was able to accomplish my original goal but I was wondering if yall could clarify for me.

If I put the command:

<input type = "radio" name = "test" value = "A">

into a jsp or asp page thats a java script command I thought?

If I put the command:

<html:radio Property = "test" Value = "test">

Then that should be a MVC or Stuts specific command is that not correct?


Thanks,
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

John Lark wrote:If I put the command:

<input type = "radio" name = "test" value = "A">

into a jsp or asp page thats a java script command I thought?

No, that's HTML.

And the proper term is markup, not command.

If I put the command:

<html:radio Property = "test" Value = "test">

Then that should be a MVC or Stuts specific command is that not correct?


That's Struts markup that's evaluated on the server. It gets turned into HTML before being sent to the browser.

MVC is a pattern, not a language.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Radio Buttons