[SOLVED] large radio button form submit

This is a discussion on "[SOLVED] large radio button form submit" within the JavaScript Forum section. This forum, and the thread "[SOLVED] large radio button form submit are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Oct 24th, 2007, 14:41
New Member
Join Date: Oct 2007
Location: uk
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy [SOLVED] large radio button form submit

Hi guys i need some advice on how to get my javascript running correctly

I have a large HTML radio button form with multiple radio button groups (40 groups 4 radio buttons per group), i have a javascript funtion which will check the radio buttons once the submit button is pressed however the code never gets past the first radio button, i dont know how to change the code so that it will dispaly all the results from the quiz.
Any help would be greatly appreciated
File attatched.
Attached Files
File Type: html test.html (25.3 KB, 10 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Oct 24th, 2007, 15:28
Up'n'Coming Member
Join Date: Jun 2007
Location: Germany
Age: 23
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Re: large radio button form submit

You have to use "document.form1.question1[0].checked". So just add "document." in front of all form1!

You should also change the action pointing to the JavaScript. Use
action="" OnSubmit="checkAnswers();"

Have fun!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Oct 25th, 2007, 08:08
New Member
Join Date: Oct 2007
Location: uk
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Re: large radio button form submit

sadly that did not work it still only displayed the result of the first question
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Oct 25th, 2007, 08:15
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: large radio button form submit

You should create an array with your answers and then cycle through the array.

Here's a start...

Code: Select all
function checkAnswers()
{
var answers = new Array(0, 1, 3, 2, 2, 2, 3, 1, 3, 2);

for (i = 1; i <= answers.length; i++)
{
	if (form1['question' + i][answers[i-1]].checked)
		document.write("Question " + i + " : correct");
	else
		document.write("Question " + i + " : incorrect");
}
}
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Oct 25th, 2007, 08:38
New Member
Join Date: Oct 2007
Location: uk
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Re: large radio button form submit

again sadly only the first result is printed, ive attatched the page with the new code
Attached Files
File Type: html test.html (25.4 KB, 4 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Oct 25th, 2007, 08:44
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: large radio button form submit

Of course! Silly me!

Try this

Code: Select all
function checkAnswers()
{
var answers = new Array(0, 0, 2, 3, 2, 1, 1, 2, 3, 0, 2, 0, 2, 0, 1, 3, 1, 2, 2, 0, 1, 3, 2, 3, 0, 1, 3, 1, 2, 2, 1, 3, 0, 1, 1, 3, 3, 1, 1, 2);

var answerString = '';
for (i = 1; i <= answers.length; i++)
{
	if (form1['question' + i][answers[i-1]].checked)
		answerString += "Question " + i + " : correct";
	else
		answerString += "Question " + i + " : incorrect";
}

document.write(answerString);
}
Everytime you call document.write, the page is destroyed so you have to store to a string first.
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Oct 25th, 2007, 08:48
New Member
Join Date: Oct 2007
Location: uk
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Talking Re: large radio button form submit



Thank you sooooooo much that has annoyed me for a day (im not the best at programming lol )

I owe you a pint
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Oct 25th, 2007, 09:03
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: large radio button form submit

No problems, everyone started programming somewhere
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
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

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
[SOLVED] Radio Button Response! :( jahphill PHP Forum 33 Oct 25th, 2007 22:15
redirecting form based on radio button values c_martini JavaScript Forum 7 Oct 9th, 2007 10:26
How do i submit a form with radio buttons ? Accurax Web Page Design 5 May 12th, 2007 18:34
Help needed with creating a radio button form sing2trees PHP Forum 1 Nov 13th, 2006 05:52
problem with radio button in form validation augustus_emperor JavaScript Forum 1 Apr 22nd, 2004 13:08


All times are GMT. The time now is 06:46.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42