Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


getElementsBy(what options)?

getElementsBy(what options)?

getElementsBy(what options)?

Is it possible to do a getElementsByType?

(or, maybe an easier question but can't find it here....I will eventually have upto 25 pairs of radio buttons that I need to pass values on to the print format page.  How is that done?)

Basically, on the print format page I need to know if name=radiobutton1 value=no was selected.  It was, then I need to write specific text on the print formated page...(ie - You have choosen to Delete this account)

I need to do that for how ever many radio groups have a selection.  Any pairs that don't have a selection I don't care about.

Ok, that question got a lot harder that I meant but my brain hurts after beating on this all day....

Dave (who thought this was going to be the easy part...)

"Credit belongs to the man who is actually in the arena - T.Roosevelt"

RE: getElementsBy(what options)?

iterate trhough the results..(for loop)


RE: getElementsBy(what options)?

AFAIK in javascript you have certain elements array (like images, forms, ...etc). try using the array document.radio to llop through all the radiobuttons...

RE: getElementsBy(what options)?

try this document.all("radio")

there is another command i think to get element by their tags. i forgot the command :(

Known is handfull, Unknown is worldfull

RE: getElementsBy(what options)?

You're probably looking for something similar to getElementsByTagName.  Here's an example that clears a form, but take note that for radio buttons (which have a tag of input, along with buttons, text fields, hidden fields, and checkboxes) you have to check type as well:


<script language=JavaScript>
function fn() {
   var inputs = document.getElementsByTagName("input");
   for (i = 0; i < inputs.length; i++) {
      if (inputs[i].type == "text") {
         inputs[i].value = "";
      if (inputs[i].type == "radio") {
         inputs[i].checked = false;
   var dropDowns = document.getElementsByTagName("select");
   for (i = 0; i < dropDowns.length; i++) {
      dropDowns[i].selectedIndex = -1;
   var textAreas = document.getElementsByTagName("textarea");
   for (i = 0; i < textAreas.length; i++) {
      textAreas[i].value = "";
<form name=blahForm>
<input type=text>FirstName<br>
<input type=text>LastName<br>
<input type=text>SSN<br>
<input type=radio name=blahRadio>Yes<br>
<input type=radio name=blahRadio>No<br>
<select multiple size=3>
<input type=button value='click me' onclick='fn()'>


RE: getElementsBy(what options)?

I am totally frustrated and my deadline is today, so I hope this doesn't come across wrong.

Those answers do not help me AT ALL.  I am new to this, only three weeks and the book they ordered me just came today.

I need to figure out which of a possible 25 radio sets has been choosen on page 1.  I need to list all the chosen radio sets, with associated values on page 2.  (This page is formatted so customer can print it off.)

So I am working on a test page for just this need (I do not want to screw up stuff I do have working.)

Page1 has this


<form name="form1" id="form1" method="post" action="print.jsp">
  <p>Pick some choices-</p>
    Yes<input name="this" type="radio" value="yes" />
    No<input name="this" type="radio" value="no" />
      Yes<input name="that" type="radio" value="yes" />
      No<input name="that" type="radio" value="no" />
   Yes<input name="other" type="radio" value="yes" />
   No<input name="other" type="radio" value="no" />
    <input type="submit" name="Submit" value="Submit" />


The second page looks like this now(justone example):


<input name="thisdata" type="hidden" value="<%= ((request.getParameter("this")!=null)?request.getParameter("this"):"") %>"  />
  <script language="javascript" type="text/javascript">
//starts table
document.write('<table width="600" border="1" align="center" cellpadding="0" cellspacing="0">');
//starts first row
//starts first column
document.write('<td width="300"><div align="center">');
//adds content in first column
document.write('You have selected This');
//ends first column
//starts second column
document.write('<td width="300"><div align="center">');
//adds content in second column
document.write('And your answer was <%= ((request.getParameter("this")!=null)?request.getParameter("this"):"") %>');
//ends second column
//ends first row and table
//add horizontal rule for easier reading on print
document.write('<hr align="center" width="75%" />');

Now, first off I know a couple of things are wrong.
1) the thisdata.value should be "==" but that seems to kill the whole thing
2) everytime I try to do 'document.thisdata.value' it becomes a null or something
3) everytime I add an else it kills the whole thing.

So, right now I am desperate and will recopy this code for all 25 possible hidden fields.  The idea being that the hidden fields in page 2 will only populate if the getParameter thing fires (that is from Dreamweaver, as I never got the answer on how to do this anotherway).

If I should just quit and start flipping burgers let me know.  I just cannot get my head around this part and stress is distracting me.

Dave (who would have loved to have LEARNED this before he was expected to do it...)

"Credit belongs to the man who is actually in the arena - T.Roosevelt"

RE: getElementsBy(what options)?

theres a few problems here:


should be

if(thisdata.value=="yes" or thisdata.value=="no")


value="<%= ((request.getParameter("this")!=null)?request.getParameter("this"):"") %>"  

should be

value="<%= ((request.getParameter('this')!=null)?request.getParameter('this'):'') %>"  

RE: getElementsBy(what options)?

The answers posted may not have helped you at all, but you should be more specific about what you're asking.  Your first question "Is it possible to do a getElementsByType?" was answered by my first post, but it obviously wasn't the answer you're looking for.

Now, to get to the matter of hand.....

You have a page that has radio buttons that can be clicked yes or no or left unclicked.  On your second page you want a printable report of what they clicked.  I see you're using JSP for your server side code.  I've never used it, but from what you've posted this should give you a working example.  From here all you'll have to do is format and tailor it the way you need it.  But it should do exactly what you're looking for:



<script language=JavaScript>
function setValues() {
   blahForm.radio1txt.value = (blahForm.radio1[0].checked) ? "yes" : (blahForm.radio1[1].checked) ? "no" : "";
   blahForm.radio2txt.value = (blahForm.radio2[0].checked) ? "yes" : (blahForm.radio2[1].checked) ? "no" : "";
   blahForm.radio3txt.value = (blahForm.radio3[0].checked) ? "yes" : (blahForm.radio3[1].checked) ? "no" : "";
   blahForm.radio4txt.value = (blahForm.radio4[0].checked) ? "yes" : (blahForm.radio4[1].checked) ? "no" : "";
   return true;
<form name=blahForm method=post action="page2.html" onsubmit="return setValues()">
<input type=radio name=radio1>yes<br>
<input type=radio name=radio1>no
<input type=hidden name=radio1txt>
<input type=radio name=radio2>yes<br>
<input type=radio name=radio2>no
<input type=hidden name=radio2txt>
<input type=radio name=radio3>yes<br>
<input type=radio name=radio3>no
<input type=hidden name=radio3txt>
<input type=radio name=radio4>yes<br>
<input type=radio name=radio4>no
<input type=hidden name=radio4txt>



<script language=JavaScript>
var txt1 = "<%=request.getParameter("radio1txt")%>";
var txt2 = "<%=request.getParameter("radio2txt")%>";
var txt3 = "<%=request.getParameter("radio3txt")%>";
var txt4 = "<%=request.getParameter("radio4txt")%>";
document.write((txt1 != "") ? "You clicked " + txt1 + " for radio button 1<br>\n" : "");
document.write((txt2 != "") ? "You clicked " + txt2 + " for radio button 2<br>\n" : "");
document.write((txt3 != "") ? "You clicked " + txt3 + " for radio button 3<br>\n" : "");
document.write((txt4 != "") ? "You clicked " + txt4 + " for radio button 4<br>\n" : "");
I'd suggest throwing the values to hidden variables for the radio sets so that you don't have to decipher what's been clicked after the page has been submitted.  This should simplify things.


RE: getElementsBy(what options)?

Thanks kaht.  That looks like it could work.  I had to run off and cobble something together to get threw the functionallity review.  (They don't know programming as long as the printed page looks like they expect.)

Also, big apology to the board, my original query was about the getByType thing since it didn't look to be acceptable programming on all the other sources I was reading.

That came from the need to collect all the radio buttons and pass the values.

(Right now I am using the Dreamweaver getParameters option to pull the values across for right now.((I changed all the values to full on text and html so that it actually writes out on the second page)).

Thanks and I will pull your programming down tomorrow and see if it works on the page.

Dave (who has something for today's deadline, thanks to many of y'alls past posts...)

"Credit belongs to the man who is actually in the arena - T.Roosevelt"

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close