/    Sign up×
Community /Pin to ProfileBookmark

Radio button onClick issue

I am creating an interactive help system that will ask some questions of the user, and based on their response via a radio button will then ask another series of questions until the solution is found.

I have been successful at changing the questions when a particular radioButton is selected but my main problem is changing the button.onclick value to a different function without it immediately executing the new function. Its almost as if I change the onclick value and it immediately recognizes that its in that event and then goes through with the new function that should be waiting on another click.

I believe the root of my problem is that I am trying to change my onclick value while inside of a function that was triggered by an onclick event.

Does anyone have any suggestions on how to change my onclick value without it immediately executing it. Or is there a better way to implement this that I’m not aware of.

[code]
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />
<title>Javascript Tester</title>
</head>

<body>

<form id=”form1″ name=”form1″ method=”post” action=””>
<textarea name=”action” id=”action” cols=”50″ rows=”3″></textarea><br />
<textarea name=”question” id=”question” cols=”50″ rows=”3″></textarea>
<table width=”445″ border=”1″>
<tr>
<th width=”41″ scope=”row”><label>
<input type=”radio” name=”radio” id=”button1″ value=”button1″ onclick=”scenario1()” />
</label></th>
<td width=”388″><label>
<textarea name=”area1″ id=”area1″ cols=”50″ rows=”3″></textarea>
</label></td>
</tr>
<tr>
<th scope=”row”><label>
<input type=”radio” name=”radio” id=”button2″ value=”button2″ onclick=”scenario1()” />
</label></th>
<td><label>
<textarea name=”area2″ id=”area2″ cols=”50″ rows=”3″></textarea>
</label></td>
</tr>
<tr>
<th scope=”row”><label>
<input type=”radio” name=”radio” id=”button3″ value=”button3″ />
</label></th>
<td><label>
<textarea name=”area3″ id=”area3″ cols=”50″ rows=”3″></textarea>
</label></td>
</tr>
</table>
</form>
</body>

<script type=”text/javascript”>
var a1 = document.getElementById(“area1”);
var a2 = document.getElementById(“area2”);
var a3 = document.getElementById(“area3”);
var b1 = document.getElementById(“button1”);
var b2 = document.getElementById(“button2”);
var b3 = document.getElementById(“button3”);
var action = document.getElementById(“action”);
var question = document.getElementById(“question”);

action.value = “You are not getting any engine RPM”;
question.value = “Which scenario accuratley depicts your problem”;
a1.value = “Displays on recorded logfile but not on LCD”;
a2.value = “Engine RPM displays on LCD but not a recorded logfile”;
a3.value = “No engine RPM on graph or LCD”;

function scenario1() {
action.value = “Hit the channel button on the LCD until Engine is displayed in the center”;
question.value = “Engine on test. Does it work correctly?”;
a1.value = “Yes”;
a2.value = “No”;
a3.value = “”;
b1.checked = false;
b1.onclick = done();
b2.onclick = scenario1a();
changeOnclick();
}

function done() {
action.value = “In the software, delete the ‘Magneto’ page from the LCD”;
question.value = “You are now done”;
a1.value = “”;
a2.value = “”;
a3.value = “”;
}
function scenario1a() {
a1.value = “scenario 1 A”;
}

</script>
</html>
[/code]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@SensiStar13authorOct 16.2009 — No replies?? Does nobody know the answer or have I joined the wrong forum?
Copy linkTweet thisAlerts:
@KorOct 16.2009 — <i>
</i>b1.onclick = [COLOR="Red"]done();[/COLOR]
b2.onclick = [COLOR="Red"]scenario1a();[/COLOR]

No. Either you call the function as a propery of the window:
<i>
</i>b1.onclick = [COLOR="Blue"]done;[/COLOR]
b2.onclick = [COLOR="Blue"]scenario1a;[/COLOR]

Or, if you need an argument to pass, on using an inner function:
<i>
</i>b1.onclick = [B][COLOR="Blue"]function(){[/COLOR][/B]done()[B][COLOR="Blue"]}[/COLOR][/B];
b2.onclick = [B][COLOR="Blue"]function(){[/COLOR][/B]scenario1a()[B][COLOR="Blue"]}[/COLOR][/B];


No replies?? Does nobody know the answer or have I joined the wrong forum?[/QUOTE]
Why are you so anxious? People here may or may not answer, depending on their knowledge and spare time. Nobody is forced to answer [I]you[/I]. After all, you had to wait only several hours. Some people may get an answer in a day or two... ?
Copy linkTweet thisAlerts:
@justinbarneskinOct 16.2009 — I look for problems to solve beginning on page three and work towards page 1 ?

Anyways, looking at SensiStar13' code, I see the logic of starting at the beginning and writing a page to get the results. I immediately saw the possibilities and so, thought of the end to write a page to get the beginning.

Here, we have 3 arrays-

Q the questions

M more info/symptoms

S the solution

Consider the arrays are more amendable, no need to rewrite HTML, only the arrays and the directions tagged to their ends. See the radio titles to see where you are going, edit your arrays to follow your path of logics.

[code=html]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Javascript Tester</title>

<SCRIPT type="text/javascript">

var Q=[ 'Which scenario accuratley depicts your problem*0~2',
'Engine on test. Does it work correctly?*3~4',
'You are not getting any engine RPM*s~1'];

var M=[ 'Displays on recorded logfile but not on LCD*s~0',
'Engine RPM displays on LCD but not a recorded logfile*q~2',
'No engine RPM on graph or LCD*q~1',
'yes*~',
'no*~']

var S=[ 'Hit the channel button on the LCD until Engine is displayed in the center',
'In the software, delete the 'Magneto' page from the LCD'];

function Qs(x,y){
if(x=='s'){document.forms['form1'].innerHTML='<textarea cols=50 rows=3>'+S[y]+'</textarea>';}
else if(x=='q'){ var p='<textarea cols=50 rows=3>'+Q[y].substring(0,Q[y].lastIndexOf('*'))+'</textarea>'; yA=Q[y].substring(Q[y].lastIndexOf('*')+1,Q[y].lastIndexOf('~'));
yZ=Q[y].substring(Q[y].lastIndexOf('~')+1,Q[y].length);
for(i=yA;i<=yZ;i++){ var Ma=M[i].substring(0,M[i].indexOf('*'))
var Deem=M[i].substring(M[i].lastIndexOf('*')+1,M[i].lastIndexOf('~'));
var Indx=M[i].substring(M[i].lastIndexOf('~')+1,M[i].length);
p+='<FIELDSET><LEGEND><input type=radio name="rado" value="'+Deem+'" onclick="Qs(''+Deem+'',''+Indx+'')" title="'+Deem+' '+Indx+'"></LEGEND><textarea cols=50 rows=3>'+Ma+'</textarea></FIELDSET>'
}
document.forms['form1'].innerHTML=p;
}

}

</SCRIPT>
</head>
<body onload="Qs('q',0)">



<form id="form1" name="form1" method="post" action="" style="width:445px;border:1px solid navy;"></form>

</body>
</HTML>[/code]
Copy linkTweet thisAlerts:
@SensiStar13authorOct 16.2009 — Thanks for the replies guys, I've got a much better handle on it now.
×

Success!

Help @SensiStar13 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...