Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Number of radiobuttons varies, what if only one!

Status
Not open for further replies.

camillaj

Programmer
Sep 18, 2003
31
AU
I have a list of radiobuttons that varies depending on the number of items that is stored in the database.

The user clicks the selected radio button and then clicks a 'get' button. I have a javascript that checks whether a radio is checked. It works fine if I have more than one radiobutton, but not if I have only one! Then 'intControlLength ' is undefined!

This is the script (I found some of this code here.):

function OpenQuestionnaire() {

var objFormField = document.form1.QuestRadioGroup;
var intControlLength = objFormField.length;
var bolSelected = false;
for (i=0;i<intControlLength;i++){
if(objFormField.checked){
bolSelected = true;
break;
}
}
if(! bolSelected){
alert(&quot;Please, choose a questionnaire.&quot;);
return false;
}else {
return true;
}
}

Can someone help me on this?

Thanks :)
 
You should change a couple of things. I won't bother listing the whole code again.

Code:
var objFormField = document.getElementsByName(&quot;QuestRadioGroup&quot;);

 ...
 ...

if(objFormField[i].checked){

HTH.
 
hi there

Have you thought of using a repeat region to increase the radio buttons

if you have yes and no as radio buttons as the questions are being pulled from the database depending how you are storing them, you could simply pull the answer and the identifer for the question lets say the row number from your table as the identifer.

you use the identifer as the name for the radio group and creat the layout for the first question to look how you want in a table cell and then simply create a repeat region for the cell to the recordset geting the questions from the database. this will create as many rows as neccessary for the amount of questions.

If you have a single table row with the abitlity to hold twenty questions and answers then you could use a if statement to hide the ones that have not had questions put into them something like this:

<%if recordset1.(&quot;question1&quot;) <> &quot;&quot; then %> question + radio buttons <%end if%>

Or simply have the array in the java script built using a repeat region so if their are lots of questions the repeat region will generate a bigger list in the array part of the javascript

It all depends on how you have built the tables to which option is best for you.

I hope this kind of gives you some ideas you can work on.
this would as well for a single radio button as well as for a couple as i have used the example of a questionaire as this is the code you have but i feel yours is more than likely for a down load option of some sort.

the questions is if you are using asp anyway why not do it completely using asp rather than addinig a java script in when you can do the same with a simple form a repeat region

I suppose it all depends on how good your understanding is of asp and some of the fun trick things that can be done.

dean

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top