...

View Full Version : Centering submit button and three output textboxes



Martin42759
08-16-2005, 04:37 PM
Could someone help me center the submit button and three output textboxes (in bold) I want them centered in my page rather than default left justified. I couldn't figure this one out, although I don't know enough about Javascrip ATM. Cheers!

<script language="JavaScript">
<!-- Quiz -->
var alphabet = '1234';
rett = 'All correct - congratulations!';

function popupMsg(rett) {
alert(rett);
}

function showQuestion(question,answer,choice1,choice2,choice3,choice4) {
var output = '<P><B>Question ' + (numberOfQuestions + 1) + ':</B> ' + question + '<P>';

for (var i = 3, j = 1; i<showQuestion.arguments.length; i++, j++) {
output += alphabet.substring(j-1,j) + '. ';
if (answer == j) output += '<INPUT TYPE="RADIO" NAME="q' + numberOfQuestions + '" VALUE="true">';
else output += '<INPUT TYPE="RADIO" NAME="q' + numberOfQuestions + '" VALUE="false">';
output += ' ' + showQuestion.arguments[i] + '<BR>';
}

numberOfQuestions++;

return output;
}

function validateAnswers() {
var correct = 0, wrong = 0, blank = 0;
for (var i=0;i<numberOfQuestions;i++) {
var CA = eval("document.quizForm.q" + i + "[0].checked");
var CB = eval("document.quizForm.q" + i + "[1].checked");
var CC = eval("document.quizForm.q" + i + "[2].checked");
var CD = eval("document.quizForm.q" + i + "[3].checked");
var AA = eval("document.quizForm.q" + i + "[0].value");
var AB = eval("document.quizForm.q" + i + "[1].value");
var AC = eval("document.quizForm.q" + i + "[2].value");
var AD = eval("document.quizForm.q" + i + "[3].value");

if (CA == CB == CC == CD) blank++;
else
if ((CA.toString() == AA) && (CB.toString() == AB) && (CC.toString() == AC) && (CD.toString() == AD))
correct++;
else wrong++;
}
document.quizForm.correct.value = correct;
document.quizForm.wrong.value = wrong;
document.quizForm.blank.value = blank;

if (correct != numberOfQuestions) return false; else popupMsg(rett); return true;
}
var numberOfQuestions = 0;
var o = '<FORM NAME="quizForm" ENCTYPE="text/plain" onSubmit="return validateAnswers()">';

o += showQuestion('Question',1,'','Answer #1','Answer #2','Answer #3','Answer #4');

o += '<P><INPUT TYPE="SUBMIT" VALUE="Click Here for Score" style= "font-family: Times New Roman, Times, serif; font-size: 10pt; background: #FFE8B7">';
o += ' Correct: <INPUT TYPE="TEXTBOX" NAME="correct" VALUE="" SIZE="2" style="background-color: #FFE8B7">';
o += ' Wrong: <INPUT TYPE="TEXTBOX" NAME="wrong" VALUE="" SIZE="2" style="background-color: #FFE8B7">';
o += ' Blank: <INPUT TYPE="TEXTBOX" NAME="blank" VALUE="" SIZE="2" style="background-color: #FFE8B7">';

o += '</FORM>';

document.write(o);
<!-- Quiz End-->
</script>

Martin42759
08-16-2005, 10:57 PM
Well I figured it out meself

o += '<center>';
o += '<P><INPUT TYPE="SUBMIT" VALUE="Click Here for Score" style= "font-family: Times New Roman, Times, serif; font-size: 10pt; background: #FFE8B7">';
o += ' Correct: <INPUT TYPE="TEXTBOX" NAME="correct" VALUE="" SIZE="2" style="background-color: #FFE8B7">';
o += ' Wrong: <INPUT TYPE="TEXTBOX" NAME="wrong" VALUE="" SIZE="2" style="background-color: #FFE8B7">';
o += ' Blank: <INPUT TYPE="TEXTBOX" NAME="blank" VALUE="" SIZE="2" style="background-color: #FFE8B7">';



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum