PDA

View Full Version : Sumit button to check radios and open page in new frame?



ashejane
02-13-2009, 02:41 AM
Hi all,

As I'm sure you'll realize I'm quite new to all of this and have never done anything with javascript before. That said I am in a course called "Computer based instruction" where I am learning to design and develop simple programs for use in classrooms. I am having difficulty with the drill I am working on. There are four options, the student need to select the correct option. When they submit the answer they will receive feedback as to whether they sected the correct answer.

I have it set up so that there are three frames (frames and the use of javascript are encourage for practice) "bar" on the left with navigational options, "main" in the center where the body of the drill is presented, and "feedback" along the bottom where the feedback will appear.

My issue is that I have everything working except the form! I'm not sure how to make it so that upon clicking the submit button the feedback is presented in the "feedback" frame. This was suggested to me but isn't working, maybe I have a mistake somewhere? Or is there another way I can do this?




<html>
<head>

<script type="text/javascript">
function CheckCheckbox() {
if q1.r1.value != 'counterfeit'{
top.frames["feedback"].location = "correct1.html";
}
else{
top.frames["feedback"].location = "incorrect1.html";
}
</script>


</head>
<body>

<form name="q1">
Jenny thought the <b>fake</b> purse looked just like the real thing!
<br>
<br>
<br>
<input type="radio" name="q1" value="abhor"> abhor
<br>
<input type="radio" name="q1" value="magnificent"> magnificent
<br>
<input type="radio" name="q1" value="counterfeit"> counterfeit
<br>
<input type="radio" name="q1" value="placid"> placid
<br>
<input type="radio" name="q1" value="abrasive">abrasive
<br>

<input type="button" name="Submit" value="Submit" onclick="CheckCheckbox()">

</form>





</body>
</html>


If anyone could help that would be great!!

Thanks so much.
If you need more information please let me know.

smansakra
02-13-2009, 04:10 AM
*you missed the '(' and '}'
*Element referenced by ID/NAME in the global scope. Use W3C standard document.getElementById() instead. use getElementById instead of q1.r1.value
*your form name is same as radio name, don't do that

below are correct one


<html>
<head>

<script type="text/javascript">


function getRadio(f, n){
f = document.forms[f].elements;
for (var i = f.length - 1; i > -1; --i)
if(f.name == n && f.checked)
return f[i].value;
return 'undefined';
}

function CheckCheckbox() {
if [I](getRadio('q1', 'r1')!= 'counterfeit'){
top.frames["feedback"].location = "correct1.html";
//alert('true');
}
else{
top.frames["feedback"].location = "incorrect1.html";
//alert('wrong');
}
[I]}
</script>


</head>
<body>

<form name="q1">
Jenny thought the <b>fake</b> purse looked just like the real thing!
<br>
<br>
<br>
<input type="radio" name="r1" value="abhor"> abhor
<br>
<input type="radio" name="r1" value="magnificent"> magnificent
<br>
<input type="radio" name="r1" value="counterfeit"> counterfeit
<br>
<input type="radio" name="r1" value="placid"> placid
<br>
<input type="radio" name="r1" value="abrasive">abrasive
<br>

<input type="button" name="Submit" value="Submit" onclick="CheckCheckbox()">

</form>





</body>
</html>

ashejane
02-13-2009, 05:17 AM
YES!!! Thank you soooo much! it works! I have been trying to figure this out for weeks. (Which I know is kinda sad since it's really not that complicated..)

Thanks a million, I can't wait to finish the drill now!

smansakra
02-13-2009, 07:49 AM
:) you're wellcome