Smart questions
Smart answers
Smart people
Join Tek-Tips Forums
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

Join Tek-Tips
*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.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

fedtrain (Instructor) (OP)
6 Jul 04 19:56
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"

krkX (Programmer)
7 Jul 04 8:53
getEmelementById
iterate trhough the results..(for loop)

KrK

DaZZleD (Programmer)
7 Jul 04 8:58
AFAIK in javascript you have certain elements array (like images, forms, ...etc). try using the array document.radio to llop through all the radiobuttons...
vbkris (Programmer)
7 Jul 04 9:08
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

Helpful Member!  kaht (Programmer)
7 Jul 04 10:10
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:

CODE

<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 = "";
   }
}
</script>
<body>
<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>
<option>blah1
<option>blah2
<option>blah3
</select>
<textarea></textarea>
<input type=button value='click me' onclick='fn()'>
</form>
</body>

-kaht

fedtrain (Instructor) (OP)
7 Jul 04 14:12
Ok,
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

CODE

<body>
<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" />
 <br>
 <br>
      Yes<input name="that" type="radio" value="yes" />
      No<input name="that" type="radio" value="no" />
<br>
<br>
   Yes<input name="other" type="radio" value="yes" />
   No<input name="other" type="radio" value="no" />
<br>
<br>
    <input type="submit" name="Submit" value="Submit" />

</form>
</body>
</html>

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

CODE

<body>
<input name="thisdata" type="hidden" value="<%= ((request.getParameter("this")!=null)?request.getParameter("this"):"") %>"  />
  <script language="javascript" type="text/javascript">
  if(thisdata.value="yes||no")
  {    
        
//starts table
document.write('<table width="600" border="1" align="center" cellpadding="0" cellspacing="0">');
//starts first row
 document.write('<tr>');
//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
 document.write('</div></td>');
//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
document.write('</div></td>');
//ends first row and table
document.write('</tr></table>');
//add horizontal rule for easier reading on print
document.write('<hr align="center" width="75%" />');
    }
}
</script>

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"

simonchristieis (Programmer)
7 Jul 04 14:23
theres a few problems here:

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


should be

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

and

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

should be

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


kaht (Programmer)
7 Jul 04 15:18
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:

CODE

page1.html:

<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;
}
</script>
<body>
<form name=blahForm method=post action="page2.html" onsubmit="return setValues()">
Radio1:<br>
<input type=radio name=radio1>yes<br>
<input type=radio name=radio1>no
<input type=hidden name=radio1txt>
<br><br>
Radio2:<br>
<input type=radio name=radio2>yes<br>
<input type=radio name=radio2>no
<input type=hidden name=radio2txt>
<br><br>
Radio3:<br>
<input type=radio name=radio3>yes<br>
<input type=radio name=radio3>no
<input type=hidden name=radio3txt>
<br><br>
Radio4:<br>
<input type=radio name=radio4>yes<br>
<input type=radio name=radio4>no
<input type=hidden name=radio4txt>
<br><br>
</form>
</body>

CODE

page2.jsp:

<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" : "");
</script>
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.

-kaht

fedtrain (Instructor) (OP)
7 Jul 04 16:53
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"

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!

Back To Forum

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