Forum Moderators: open

Message Too Old, No Replies

help with onclick function

         

useless

7:12 pm on Feb 25, 2005 (gmt 0)

10+ Year Member



I am trying to re-post this question as the last time it went into some sort of holding/scan status. Anyways, I'm not very good with js and am looking for a way to fill a <span> tag with a correct/incorrect message based on a radio button selection. I know this can be done, but what is putting a bit of twist on this is not being able to name the form. This is where I am having difficulty with adding a function to the onclick event to achieve the desired span result. Any suggestions are appreciated.

birdbrain

12:24 pm on Feb 26, 2005 (gmt 0)



Hi there useless,

try this, it may suit your requirements...


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>radio button swap text</title>

<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />

<script type="text/javascript">
//<![CDATA[

function fillSpan(n,m,words) {

if(document.forms[0][n].checked==true) {
document.forms[0][n].checked=false;
document.forms[0][m].checked=true;
}
document.getElementById("word").innerHTML=words;
}

//]]>
</script>

</head>
<body>

<form action="#">
<div>
<label>
<input type="radio" checked="checked" value="a correct" onclick="fillSpan(1,0,this.value)"/>
: correct</label>
</div>
<div>
<label>
<input type="radio" value="an incorrect" onclick="fillSpan(0,1,this.value)"/>
: incorrect</label>
</div>
</form>

<div>
this message is <span id="word">a correct</span> statement.
</div>

</body>
</html>

birdbrain

useless

5:45 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



Hi BirdBrain,

Thanks for this input, however as I am not very good with JS (hence the name 'useless'), I am still a little confused how to change the function that you have created to suit my needs. If I have a number of questions (say 10) how do I need to change that function so that the span id is recognized for each question? That is to say that each question will need to display a correct/incorrect answer.

Thanks again,

useless