Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

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.

LINK TO THIS FORUM!

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

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...with companys cutting back on training, lack of true support by makers of software, the forums are a great tool in your cyber-toolbox...."

Geography

Where in the world do Tek-Tips members come from?

Please help - document[frmName] is undefined when calling function with variable form nameHelpful Member! 

Katerine (Programmer)
25 May 12 14:16
Hi,
I need help - this has officially gotten beyond me, I think. dazed

I have a form that's dynamically created through vbscript (it has to be that way... one form, many course choices, many different questions for each course), and need it to validate that all multiple-choice answers are filled in (default values are unfortunately not an option). Here are the basic facts:

Test browser/system: Firefox 12.0, Windows 7 64-bit

Symptom: When I hit the submit button, the form goes through, even if I didn't answer anything.

What it should do: If there are any radio-button questions in the form, they must all be filled in.

Errors: When I hit submit, after it mistakenly goes through, and I look at the error console, I see the error message, "document[frmName] is undefined"

Notes that are probably not relevant but I'll include them anyway:
- I'm testing this on my test server (localhost/insertvirtualnamehere/) before I put this into production. This is where the problems are occurring. Obviously, I can't put them on the production server until it's fixed on localhost first.
- The validate function is dynamically generated in vbscript, based on the same table that creates the questions. New lines in the function are created with vbNewLine.

Barebones code with a few example questions, that the vbScript returns is as follows:

CODE

<?xml version="1.0" encoding="windows-1252"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <script type="text/javascript"> <!-- var invalids = "!%&*()-+,';\"\\" function getRadioVal(radioObj){ if(!radioObj) return ""; var radioLength = radioObj.length; if(radioLength == undefined) if(radioObj.checked) return radioObj.value; else return ""; for(var i = 0; i < radioLength; i++) { if(radioObj[i].checked) { return radioObj[i].value; } } return ""; } // --> </script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Insert Title here</title><link href="stylesheets/style.css" rel="stylesheet" type="text/css" /><link href="stylesheets/dotcomstyle.css" rel="stylesheet" type="text/css" /><link rel="icon" type="image/gif" href="images/icon.gif"> <link rel="stylesheet" href="stylesheets/forms.css" type="text/css" /> <style type="text/css"> </style> <script type="text/javascript"> <!-- function checkRadio (frmName, rbGroupName) { var radios = document[frmName].elements[rbGroupName]; for (var i=0; i <radios.length; i++) { if (radios[i].checked) { return true; } } return false; } function validate() { if (!checkRadio("evalform","EvalCtrl387")) { alert("You must answer all Yes/No and 1/2/3/4/5 questions. Please double-check all of the answers and try again"); return false; } if (!checkRadio("evalform","EvalCtrl388")) { alert("You must answer all Yes/No and 1/2/3/4/5 questions. Please double-check all of the answers and try again"); return false; } if (!checkRadio("evalform","EvalCtrl389")) { alert("You must answer all Yes/No and 1/2/3/4/5 questions. Please double-check all of the answers and try again"); return false; } if (!checkRadio("evalform","EvalCtrl400")) { alert("You must answer all Yes/No and 1/2/3/4/5 questions. Please double-check all of the answers and try again"); return false; } } // --> </script> </head> <body> <div id="container"> <div class="section"> <h1>Insert name of page here</h1> <h2>Insert name of class here</h2> <p style="font-size:1.05em;font-weight:bold;">Please complete the form below to evaluate this session.</p> </div> <div class="section"> <form id="evalform" action="evalcert_evalquestions.asp" method="post" onsubmit="return validate();"> <input type="hidden" name="evalcontentid" value="2" /> <input type="hidden" name="classid" value="528" /> <input type="hidden" name="evaltype" value="session" /> <div class="minorcategory"> <div class="head">At the end of this program, I was able to:</div> <div class="question"> <div class="text">Identify your facilities bylaws.</div> <div class="answer"> <div><input type="radio" name="EvalCtrl387" value="5" />5 - Strongly agree</div> <div><input type="radio" name="EvalCtrl387" value="4" />4 - Agree</div> <div><input type="radio" name="EvalCtrl387" value="3" />3 - Neutral</div> <div><input type="radio" name="EvalCtrl387" value="2" />2 - Disagree</div> <div><input type="radio" name="EvalCtrl387" value="1" />1 - Strongly Disagree</div> </div> </div> <div class="question"> <div class="text">Identify who sets, defines, writes and updates the bylaws.</div> <div class="answer"> <div><input type="radio" name="EvalCtrl388" value="5" />5 - Strongly agree</div> <div><input type="radio" name="EvalCtrl388" value="4" />4 - Agree</div> <div><input type="radio" name="EvalCtrl388" value="3" />3 - Neutral</div> <div><input type="radio" name="EvalCtrl388" value="2" />2 - Disagree</div> <div><input type="radio" name="EvalCtrl388" value="1" />1 - Strongly Disagree</div> </div> </div> <div class="question"> <div class="text">Identify wording, definitions and differences of the bylaws.</div> <div class="answer"> <div><input type="radio" name="EvalCtrl389" value="5" />5 - Strongly agree</div> <div><input type="radio" name="EvalCtrl389" value="4" />4 - Agree</div> <div><input type="radio" name="EvalCtrl389" value="3" />3 - Neutral</div> <div><input type="radio" name="EvalCtrl389" value="2" />2 - Disagree</div> <div><input type="radio" name="EvalCtrl389" value="1" />1 - Strongly Disagree</div> </div> </div> </div> <div class="minorcategory"> <div class="question"> <div class="text">Did you as a participant notice any bias that was not previously disclosed in this program? </div> <div class="answer"> <div><input type="radio" name="EvalCtrl400" value="1" />Yes</div> <div><input type="radio" name="EvalCtrl400" value="0" />No</div> </div> </div> <div class="question"> <div class="text">If yes, please describe who was biased and how.</div> <div class="answer"> <div><textarea name="EvalCtrl401" cols="40" rows="5"></textarea></div> </div> </div> </div> <div class="lblstandout"> Click "submit" below to complete the evaluation.<br /><input type="hidden" name="evalform" value="submit" /><input type="image" src="images/button_submit_nls.gif" alt="Submit" /> </div> </form></div> </body> </html>

Many thanks!

Katie

Helpful Member!  feherke (Programmer)
25 May 12 14:30
Hi

document has no evalform property. Maybe :

CODE --> fragment

var radios = document.forms[frmName].elements[rbGroupName];
But as there in no form with name evalform, neither that will work.

As evalform is an id, use it as such :

CODE --> fragment

var radios = document.getElementById(frmName).elements[rbGroupName];

Feherke.
http://feherke.github.com/

Katerine (Programmer)
25 May 12 15:53
Many thanks - worked like a charm! 2thumbsup

Katie

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