Click to See Complete Forum and Search --> : radio button enables some other radio buttons


mf22cs
05-11-2004, 04:46 AM
Hi,

I have 19 radio buttons that represent cities, that
you may travel from... you must pick one of them.

Then you have, on the same page, 19 radio buttons that
represents cities, that you may travel to...

Now I wish to disable some of the later based on what
city you go from.

Rules:

City A and B may or may not be in the same region.
You can not go from city A to city A, not even if there multiple stops in that city.
You can not go from city A to city B, if A and B are in the same region.


Any suggestions?

/marcus

Pittimann
05-11-2004, 04:49 AM
Hi!

Can you please post your HTML and also point out, which cities are in which region?

Cheers - Pit

mf22cs
05-11-2004, 04:59 AM
<table style="width: 500px;">
<tr>
<td><input type="radio" name="from" id="f10001" value="10001" onclick="enableTo(1)" /><label for="f10001">Skövde</label></td>
<td><input type="radio" name="from" id="f10006" value="10006" onclick="enableTo(1)" /><label for="f10006">Mölltorp</label></td>
<td><input type="radio" name="from" id="f10011" value="10011" onclick="enableTo(2)" /><label for="f10011">Igelbäcken</label></td>
<td><input type="radio" name="from" id="f10016" value="10016" onclick="enableTo(3)" /><label for="f10016">Strängnäs</label></td>
</tr>
<tr>
<td><input type="radio" name="from" id="f10002" value="10002" onclick="enableTo(1)" /><label for="f10002">Igelstorp</label></td>
<td><input type="radio" name="from" id="f10007" value="10007" onclick="enableTo(1)" /><label for="f10007">Karlsborg</label></td>
<td><input type="radio" name="from" id="f10012" value="10012" onclick="enableTo(2)" /><label for="f10012">Olshammar</label></td>
<td><input type="radio" name="from" id="f10017" value="10017" onclick="enableTo(3)" /><label for="f10017">Läggesta</label></td>
</tr>
<tr>
<td><input type="radio" name="from" id="f10003" value="10003" onclick="enableTo(1)" /><label for="f10003">Västanå</label></td>
<td><input type="radio" name="from" id="f10008" value="10008" onclick="enableTo(1)" /><label for="f10008">Svanvik</label></td>
<td><input type="radio" name="from" id="f10013" value="10013" onclick="enableTo(2)" /><label for="f10013">Askersund</label></td>
<td><input type="radio" name="from" id="f10018" value="10018" onclick="enableTo(3)" /><label for="f10018">Södertälje</label></td>
</tr>
<tr>
<td><input type="radio" name="from" id="f10004" value="10004" onclick="enableTo(1)" /><label for="f10004">Tibro</label></td>
<td><input type="radio" name="from" id="f10009" value="10009" onclick="enableTo(1)" /><label for="f10009">Granvik</label></td>
<td><input type="radio" name="from" id="f10014" value="10014" onclick="enableTo(2)" /><label for="f10014">Örebro</label></td>
<td><input type="radio" name="from" id="f10019" value="10019" onclick="enableTo(3)" /><label for="f10019">Stockholm</label></td>
</tr>
<tr>
<td><input type="radio" name="from" id="f10005" value="10005" onclick="enableTo(1)" /><label for="f10005">Fagersanna</label></td>
<td><input type="radio" name="from" id="f10010" value="10010" onclick="enableTo(1)" /><label for="f10010">Sörhamn</label></td>
<td><input type="radio" name="from" id="f10015" value="10015" onclick="enableTo(3)" /><label for="f10015">Eskilstuna</label></td>
<td>&nbsp;</td>
</tr>
</table>


The "onclick" is the beginning of some sort solution... but I get stuck...

Same region are those with the same region id, in onclick="enabelTo(?)"...

The second set of radiobuttons are pretty much the same, but with the "onclick" deleted, and the "id" modified on this pattern:

id="t[same as value]r[region id]"

/marcus

mf22cs
05-11-2004, 05:08 AM
Is it possible to access multiple elements by matching them to "regexp"?

For example:

the pattern:

t\d{5}r2

match the following:

t10010r2
t10017r2

but not:

t10008r1
t10016r4

/marcus

Pittimann
05-11-2004, 05:27 AM
Hi!

Something like that will do the job<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
function enableTo(region){
var where=document.forms[0].to;
var len=where.length;
for(var i=0;i<len;i++){
var doEnable=Number(where[i].id.substring(7,8));
if (doEnable!=region){
where[i].disabled=false;
}
if (doEnable==region){
where[i].disabled=true;
where[i].checked=false;
}
}
}
//-->
</script>
</head>
<body>
<form>
from:
<table style="width: 500px;">
<tr>
<td><input type="radio" name="from" id="f10001" value="10001" onclick="enableTo(1)" /><label for="f10001">Skövde</label></td>
<td><input type="radio" name="from" id="f10006" value="10006" onclick="enableTo(1)" /><label for="f10006">Mölltorp</label></td>
<td><input type="radio" name="from" id="f10011" value="10011" onclick="enableTo(2)" /><label for="f10011">Igelbäcken</label></td>
<td><input type="radio" name="from" id="f10016" value="10016" onclick="enableTo(3)" /><label for="f10016">Strängnäs</label></td>
</tr>
<tr>
<td><input type="radio" name="from" id="f10002" value="10002" onclick="enableTo(1)" /><label for="f10002">Igelstorp</label></td>
<td><input type="radio" name="from" id="f10007" value="10007" onclick="enableTo(1)" /><label for="f10007">Karlsborg</label></td>
<td><input type="radio" name="from" id="f10012" value="10012" onclick="enableTo(2)" /><label for="f10012">Olshammar</label></td>
<td><input type="radio" name="from" id="f10017" value="10017" onclick="enableTo(3)" /><label for="f10017">Läggesta</label></td>
</tr>
<tr>
<td><input type="radio" name="from" id="f10003" value="10003" onclick="enableTo(1)" /><label for="f10003">Västanå</label></td>
<td><input type="radio" name="from" id="f10008" value="10008" onclick="enableTo(1)" /><label for="f10008">Svanvik</label></td>
<td><input type="radio" name="from" id="f10013" value="10013" onclick="enableTo(2)" /><label for="f10013">Askersund</label></td>
<td><input type="radio" name="from" id="f10018" value="10018" onclick="enableTo(3)" /><label for="f10018">Södertälje</label></td>
</tr>
<tr>
<td><input type="radio" name="from" id="f10004" value="10004" onclick="enableTo(1)" /><label for="f10004">Tibro</label></td>
<td><input type="radio" name="from" id="f10009" value="10009" onclick="enableTo(1)" /><label for="f10009">Granvik</label></td>
<td><input type="radio" name="from" id="f10014" value="10014" onclick="enableTo(2)" /><label for="f10014">Örebro</label></td>
<td><input type="radio" name="from" id="f10019" value="10019" onclick="enableTo(3)" /><label for="f10019">Stockholm</label></td>
</tr>
<tr>
<td><input type="radio" name="from" id="f10005" value="10005" onclick="enableTo(1)" /><label for="f10005">Fagersanna</label></td>
<td><input type="radio" name="from" id="f10010" value="10010" onclick="enableTo(1)" /><label for="f10010">Sörhamn</label></td>
<td><input type="radio" name="from" id="f10015" value="10015" onclick="enableTo(3)" /><label for="f10015">Eskilstuna</label></td>
<td> </td>
</tr>
</table>
<br>
to:
<table style="width: 500px;">
<tr>
<td><input type="radio" name="to" id="t10001r1" value="10001" disabled /><label for="t10001r1">Skövde</label></td>
<td><input type="radio" name="to" id="t10006r1" value="10006" disabled /><label for="t10006r1">Mölltorp</label></td>
<td><input type="radio" name="to" id="t10011r2" value="10011" disabled /><label for="t10011r2">Igelbäcken</label></td>
<td><input type="radio" name="to" id="t10016r3" value="10016" disabled /><label for="t10016r3">Strängnäs</label></td>
</tr>
<tr>
<td><input type="radio" name="to" id="t10002r1" value="10002" disabled /><label for="t10002r1">Igelstorp</label></td>
<td><input type="radio" name="to" id="t10007r1" value="10007" disabled /><label for="t10007r1">Karlsborg</label></td>
<td><input type="radio" name="to" id="t10012r2" value="10012" disabled /><label for="t10012r2">Olshammar</label></td>
<td><input type="radio" name="to" id="t10017r3" value="10017" disabled /><label for="t10017r3">Läggesta</label></td>
</tr>
<tr>
<td><input type="radio" name="to" id="t10003r1" value="10003" disabled /><label for="t10003r1">Västanå</label></td>
<td><input type="radio" name="to" id="t10008r1" value="10008" disabled /><label for="t10008r1">Svanvik</label></td>
<td><input type="radio" name="to" id="t10013r2" value="10013" disabled /><label for="t10013r2">Askersund</label></td>
<td><input type="radio" name="to" id="t10018r3" value="10018" disabled /><label for="t10018r3">Södertälje</label></td>
</tr>
<tr>
<td><input type="radio" name="to" id="t10004r1" value="10004" disabled /><label for="t10004r1">Tibro</label></td>
<td><input type="radio" name="to" id="t10009r1" value="10009" disabled /><label for="t10009r1">Granvik</label></td>
<td><input type="radio" name="to" id="t10014r2" value="10014" disabled /><label for="t10014r2">Örebro</label></td>
<td><input type="radio" name="to" id="t10019r3" value="10019" disabled /><label for="t10019r3">Stockholm</label></td>
</tr>
<tr>
<td><input type="radio" name="to" id="t10005r1" value="10005" disabled /><label for="t10005r1">Fagersanna</label></td>
<td><input type="radio" name="to" id="t10010r1" value="10010" disabled /><label for="t10010r1">Sörhamn</label></td>
<td><input type="radio" name="to" id="t10015r3" value="10015" disabled /><label for="t10015r3">Eskilstuna</label></td>
<td> </td>
</tr>
</table>
</form>
</body>
</html>Cheers - Pit

mf22cs
05-11-2004, 06:40 AM
Back from lunch... I'll check in to that code of yours... it seem to be what i look for..:)

Thanks!
/Marcus

Pittimann
05-11-2004, 06:44 AM
Hi!

I hope, lunch was nice :D; if you need modifications or something, just post again...

Cheers - Pit

mf22cs
05-11-2004, 07:00 AM
Well only minor modifications, that I could take care of myself.

Thanks a lot!
/marcus

Pittimann
05-11-2004, 07:02 AM
Hi!

You're welcome! ;)

Cheers - Pit