Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > JavaScript

Reply
 
LinkBack Thread Tools
Old March 26th, 2009, 05:38 PM   #1
New Member
 

Join Date: Mar 2009
Location: New Zealand
Age: 20
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Nate is on a distinguished road
JavaScript store radio button answer

Hi i'm new to this so ok I have a simple XHTML form with 8 radio button options for each question, I have 20 questions, each is pulled from an XML file. I have managed to construct the JavaScript to validate that an option has to be selected but I need a way to store each questions answer when you move onto the next question, maybe as a string or an array??? Please help!!! Thanks.

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="style.css" rel="stylesheet" type="text/css" />
<xml id="staffInfo" src="questions.xml"></xml>
<title>MonsterSurvey</title>
<script language="javascript" type="text/javascript">
<!--
function submitIt(survey){

//Checks question/answer radio button
answerOption = -1
for (i=0; i<survey.answer.length; i++){
if (survey.answer[i].checked){
answerOption = i
}
}
if(answerOption == -1){
alert("You need to select an answer on the scale of 1-7 or N/A");
return false;
}

return true;
}
// -->
</script>
</head>

<body>
<form action="http://www.cknuckles.com/cgi/echo.cgi" method="post" name="survey" onsubmit="return submitIt(this)">
<table width="770">
<tr>
<td colspan="9"><span datasrc="#staffInfo" datafld="question"></span></td>
<tr>
<td width="190"><statement>Not at all true of me</statement></td>
<td width="50" align="center"><answer> 1</answer></td>
<td width="50" align="center"><answer>2</answer></td>
<td width="50" align="center"><answer>3</answer></td>
<td width="50" align="center"><answer>4</answer></td>
<td width="50" align="center"><answer>5</answer></td>
<td width="50" align="center"><answer>6</answer></td>
<td width="50" align="center"><answer>7</answer></td>
<td width="50" align="center"><answer>N/A</answer></td>
<td width="190"><statement>Very true of me</statement></td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="center"><input type="radio" name="answer" value="1" /></td>
<td align="center"><input type="radio" name="answer" value="2" /></td>
<td align="center"><input type="radio" name="answer" value="3" /></td>
<td align="center"><input type="radio" name="answer" value="4" /></td>
<td align="center"><input type="radio" name="answer" value="5" /></td>
<td align="center"><input type="radio" name="answer" value="6" /></td>
<td align="center"><input type="radio" name="answer" value="7" /></td>
<td align="center"><input type="radio" name="answer" value="NA" /></td>
</tr>
</table>
<button onclick="staffInfo.recordset.moveNext();
if (staffInfo.recordset.EOF) staffInfo.recordset.moveFirst()">Next Question</button>
<br /><br />
<input type="submit" value="Submit Answers" />
</form>
</body>
</html>
Nate is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks

Tags
array , javascript , radio button , store , string , xhtml , xml


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Radio Button Problems in ActionScript 3.0 dgstarr Flash and ActionScript 1 September 6th, 2007 02:11 PM
radio button interfering with drop down antonyx JavaScript 1 April 26th, 2007 09:11 PM
Any way to use an image for a radio button? masonbarge HTML, XHTML and CSS 23 January 6th, 2007 06:06 AM
automatic pop-up when click on a radio button joshcxa JavaScript 2 August 1st, 2006 03:06 AM
Delete All Row (Select All Row Using Radio Button) Monie Classic ASP 37 November 5th, 2004 06:21 AM


Search Engine Optimization by vBSEO 3.2.0 RC8