File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting the Value of a RadioButton on Load

 
Steve Dyke
Ranch Hand
Posts: 1602
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to use JavaScript to set the value of a RadioButton group but I can't get it to work.

 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what is happening? Error Message? You setting it onload?

Eric
 
Steve Dyke
Ranch Hand
Posts: 1602
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The radio group is not getting a value at all. The radio group does not have any selected item(first item should have a dot in it). It should have the first item selected since the value of the variable I am using is 1.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Set the checked property of the first radio element to true.
 
Steve Dyke
Ranch Hand
Posts: 1602
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you help with the syntax? I can't seem to be able to povide the correct reference to set the checked property.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
document.formName.radioName[0].checked = true;
 
Steve Dyke
Ranch Hand
Posts: 1602
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I use this syntax I get an error that this is either not an object or is null.
 
Steve Dyke
Ranch Hand
Posts: 1602
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still have not got this to work yet. Can you tell me why I have errors on the syntax yo suggested? I can never get the following syntax to work in my JavaScripts for JSF for some reason. It will work in JSP though.

document.form1.text3.value = "Steve";
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Steve Dyke
Ranch Hand
Posts: 1602
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried several differnt things to get this to work. The first two lines of this code work but the third one will not. Note the radio1 button group is located in a tabbedPanel.

 
Steve Dyke
Ranch Hand
Posts: 1602
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This might not make any sense but if I put an alert() at the end of my JavaScript, I run the page, then I refresh the page, the radio buton is checked as expected. But after I click the ok on the alert the radio button becomes unchecked.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a race condition to me. Are you sure that you are waiting until the document is loaded to try and manipulate the DOM?

Also "tabbedPanel" is not an HTML construct and is meaningless in this forum.
 
Steve Dyke
Ranch Hand
Posts: 1602
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am firing my function in the onload event. If it is a race problem it does not seem that one radio button would have the checked property set and disreguard the second radio button.

If I could I would like to explain what I need to accomplish. My web app loads data from a connection to a data record using a servlet. this data record is based on user input selection. I assign the field values to variables. The user can open another form to modify the record data. Initialally the form controls are empty, the user fills out what ever and saves the form. This writes data into the data record. Later if the user calls the form I need it populated with data thats already been put in.

I don't know if this is this correct way or not. I have everthing working except the form populating with the pre-saved data.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you doing it only the client side rather than setting it in the markup generated on the server?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic