...

View Full Version : Radio Buttons and Switch Statements HELP



codingcodeddode
11-27-2012, 02:10 AM
How could I get a string to be sent to the textbox depending on which radio button is clicked? MUST BE RADIO BUTTONS AND MUST USE SWITCH STRUCTURE

heres my code.



<body>
<form id='form'>
<input type='radio' name='week' value='sunday' id='sunday' onclick='runme();'>Sunday<br>
<input type='radio' name='week' value='monday' id='monday' onclick='runme();'>Monday<br>
<input type='radio' name='week' value='tuesday' id='tuesday' onclick='runme();'>Tuesday<br>
<input type='radio' name='week' value='wednssday' id='wednesday' onclick='runme();'>Wednesday<br>
<input type='radio' name='week' value='thursday' id='thursday' onclick='runme();'>Thursday<br>
<input type='radio' name='week' value='friday' id='friday' onclick='runme();'>Friday<br>
<input type='radio' name='week' value='saturday' id='saturday' onclick='runme();'>Saturday<br>
<input value='This is ' id='textBox'>
</form>
</body>

Old Pedant
11-27-2012, 02:30 AM
Well, you already have an onclick there on each radio button, so what do YOU think the code in the runme function might look like?

I have to say that s switch is ALMOST the worst possible choice for this. I have to assume it is yet another idiotic homework assignment given you by yet another incompetent instructor. No?

Old Pedant
11-27-2012, 02:35 AM
I know you can't do it this way, but this is the simplest and most efficient:


<body>
<form id='form'>
<input type='radio' name='week' value='Sunday'>Sunday<br>
<input type='radio' name='week' value='Monday'>Monday<br>
<input type='radio' name='week' value='Tuesday'>Tuesday<br>
<input type='radio' name='week' value='Wednesday' >Wednesday<br>
<input type='radio' name='week' value='Thursday' >Thursday<br>
<input type='radio' name='week' value='Friday' >Friday<br>
<input type='radio' name='week' value='Saturday' >Saturday<br>
<input name="weekday" >
</form>

<script type="text/javascript">
(
function( )
{
var f = document.getElementById("form");

var rbs = f.week;
for ( var r = 0; r < rbs.length; ++r )
{
rbs[r].onclick = getWeekday;
}
function getWeekday( )
{
f.weekday.value = "You chose " + this.value;
}
}
)();
</script>
</body>
</html>

codingcodeddode
11-27-2012, 02:37 AM
Well, you already have an onclick there on each radio button, so what do YOU think the code in the runme function might look like?

I have to say that s switch is ALMOST the worst possible choice for this. I have to assume it is yet another idiotic homework assignment given you by yet another incompetent instructor. No?

Thats what i thought, I had already done this very easily with an if statement, but, yes sadly less funding leads to the employment of unfit instructors. There are several students who seem to know more than the instructor lol!

THANK GOODNESS FOR FORMS AND PEOPLE LIKE YOU!

Old Pedant
11-27-2012, 03:32 AM
As ugly as it is, I think you may have to do something like this:


<input type='radio' name='week' value='sunday' onclick='runme(this);'>Sunday<br

and then your runme will have to do something like:


function runme( rb )
{
var rbValue = rb.value;
var message;
switch( rbValue )
{
"sunday": message = "You chose Sunday"; break;
... etc. ...
}
... put message into text field ...
}

It's so stupid. A useless usage of switch. But if that's what doofus wants, that's what doofus gets.

Philip M
11-27-2012, 10:21 AM
Is there any other subject in your school - law, medicine, math, French, whatever, where the teachers are incompetent and the students are more knowledgeable? Why is it imagined that any doofus (presumany a failure in some other field) can teach computer programming?

codingcodeddode
11-27-2012, 06:56 PM
Is there any other subject in your school - law, medicine, math, French, whatever, where the teachers are incompetent and the students are more knowledgeable? Why is it imagined that any doofus (presumany a failure in some other field) can teach computer programming?

Well i haven't noticed any other instructors as terrible as this guy, but then again I haven't been attending long enough to notice. All my other instructors are, i don't want to say great, but their not terrible.

How I admire this nations education system!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum