|
|||||||
| JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...) |
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Need occurance number of radio button
I have six sets of radio buttons, each with at least six options and only need the occurance number of each set for a calculation. Is there a way to easily identify which button in each set was selected? TIA
|
|
#2
|
||||
|
||||
|
Assuming I understand what you want ...
![]() Assign a unique 'id=' in addition to the 'name=' for each group. Use the id info to determine which option selected from each group. Since you have not posted any code, this is just a guess as to what you want. Code:
Group 1: <input type="radio" name="rbtn1" id="rbtn10" value="10"> <input type="radio" name="rbtn1" id="rbtn11" value="11"> <input type="radio" name="rbtn1" id="rbtn12" value="12"> <input type="radio" name="rbtn1" id="rbtn13" value="13"> <input type="radio" name="rbtn1" id="rbtn14" value="14"> <input type="radio" name="rbtn1" id="rbtn15" value="15"> Group 2: <input type="radio" name="rbtn2" id="rbtn20" value="20"> <input type="radio" name="rbtn2" id="rbtn21" value="21"> <input type="radio" name="rbtn2" id="rbtn22" value="22"> <input type="radio" name="rbtn2" id="rbtn23" value="23"> <input type="radio" name="rbtn2" id="rbtn24" value="24"> <input type="radio" name="rbtn2" id="rbtn25" value="25"> // etc. ![]() If you don't post some code, you get what we think you want which is not necessarily what you want! |
|
#3
|
|||
|
|||
|
Quote:
Code:
<form>
<input type="radio" name="myGroup" onclick='this.value = getIndex( this ); alert(this.value)'>
.......
</form>
<script type='text/javascript'>
function getIndex( elem )
{
var group = elem.form[ elem.name ], len = group.length;
for( var i = 0; group[ i ] != elem; i++ )
;
return i;
}
</script>
__________________
scripterlative.com |
|
#4
|
|||
|
|||
|
Thanks. This is a sample from my table:
Quote:
|
|
#5
|
||||
|
||||
|
I'm still unclear as to final purpose
, but this might get you further down the road. ![]() What do the 'X', 'O' and '---' represent? Code:
<html>
<head>
<title>Music Notation</title>
<script type="text/javascript">
// For: http://www.webdeveloper.com/forum/showthread.php?p=1067076#post1067076
function getRBtnName(GrpName) {
var sel = document.getElementsByName(GrpName);
var fnd = -1;
var str = '';
for (var i=0; i<sel.length; i++) {
if (sel[i].checked == true) { str = sel[i].value; fnd = i; }
}
// return fnd; // return option index of selection
// comment out next line if option index used in line above
return str;
}
function ResetRBtns() {
var sel = document.getElementsByName('S6'); for (var i=0; i<sel.length; i++) { sel[i].checked = false; }
sel = document.getElementsByName('S5'); for (var i=0; i<sel.length; i++) { sel[i].checked = false; }
sel = document.getElementsByName('S4'); for (var i=0; i<sel.length; i++) { sel[i].checked = false; }
sel = document.getElementsByName('S3'); for (var i=0; i<sel.length; i++) { sel[i].checked = false; }
sel = document.getElementsByName('S2'); for (var i=0; i<sel.length; i++) { sel[i].checked = false; }
sel = document.getElementsByName('S1'); for (var i=0; i<sel.length; i++) { sel[i].checked = false; }
}
function CurrentPositions() {
var str = getRBtnName('S6')+'|'+getRBtnName('S5')+'|'+getRBtnName('S4')+'|'
+ getRBtnName('S3')+'|'+getRBtnName('S2')+'|'+getRBtnName('S1');
return str;
}
</script>
</head>
<body>
<table border="1">
<tr>
<td>X</td>
<td><input type="radio" name="S6" value="60"></td>
<td><input type="radio" name="S5" value="50"></td>
<td><input type="radio" name="S4" value="40"></td>
<td><input type="radio" name="S3" value="30"></td>
<td><input type="radio" name="S2" value="20"></td>
<td><input type="radio" name="S1" value="10"></td>
<td>X</td>
</tr>
<tr>
<td>O</td>
<td><input type="radio" name="S6" value="61"></td>
<td><input type="radio" name="S5" value="51"></td>
<td><input type="radio" name="S4" value="41"></td>
<td><input type="radio" name="S3" value="31"></td>
<td><input type="radio" name="S2" value="21"></td>
<td><input type="radio" name="S1" value="11"></td>
<td>O</td>
</tr>
<tr>
<td>--</td>
<td><input type="radio" name="S6" value="62"></td>
<td><input type="radio" name="S5" value="52"></td>
<td><input type="radio" name="S4" value="42"></td>
<td><input type="radio" name="S3" value="32"></td>
<td><input type="radio" name="S2" value="22"></td>
<td><input type="radio" name="S1" value="12"></td>
<td>--</td>
</tr>
</table>
<button onclick="alert(CurrentPositions())">Current Positions</button>
<button onclick="ResetRBtns()">Reset</button>
</body>
</html>
You will need to use another function to decode the results (only displayed in current alert) to do with the information as you please. Decoded, "S62" would represent 'String 6 - Fret 2" ??? Good Luck!
|
|
#6
|
|||
|
|||
|
X represents an unplayed string for that chord, probably on the outside (one of the E strings). O is an open string and ---- represents a fret. When zero (an X) is selected that string is ignored, otherwise an occurance number is added to a different constant for each string to create part of a chord. The constant for the B string would be a subscript for the entry of A# in another table since, for an open string, 1 would be added to that constant. This is part of that table, all notes are either sharp or natural and are offset by displacement from the 3rd line.
Code:
var offsets = [ "n-11", "n-10", "#-10", "n-9", "#-9", "n-8", "#-8", "n-7",
|
|
#7
|
||||
|
||||
|
You're most welcome.
Happy to help. BTW, play banjo myself. No need for that extra guitar string. 5 fingers ... 5 strings ... perfect! ![]() Good Luck!
|
|
#9
|
||||
|
||||
|
Nice work.
![]() Absolutely nothing wrong with your program, but I got a notion that I could compress it some more. ![]() Might load a fraction faster and should be easier to maintain and/or modify in the future. ![]() Code:
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta name="description" content="Generate guitar chords to be used in NoteWorthy Composer">
<meta name="keywords" content="'guitar chords', noteworthy, composer">
<title>Generate guitar chords</title>
<script language="JavaScript">
function readRadio(i) {
var sel = document.getElementsByName("S"+(6-i));
for (var i=0; i<sel.length; i++) {
if (sel[i].checked == true) return i;
}
}
function setRadio(parm) {
for (var i=0; i < 6; i++) {
var sel = document.getElementsByName("S"+(6-i));
sel[parseInt(parm.charAt(i))].checked = true;
}
}
function startup() {
document.nwcform.selAll.checked = true;
setRadio("000000");
}
function doChords() {
var offsets = [
"n-11", "n-10", "#-10", "n-9", "#-9", "n-8", "#-8", "n-7",
"n-6", "#-6", "n-5", "#-5", "n-4", "n-3", "#-3", "n-2", "#-2", "n-1", "#-1", "n0",
"n1", "#1", "n2", "#2", "n3", "n4", "#4", "n5", "#5", "n6", "#6"
];
var stringEntry = [ 0, 5, 10, 15, 19, 24 ];
var i, j, cntNotes=0, OutText = "", buildOffsets="";
OutText = "!NoteWorthyComposerClip(2.0,Single)\n";
for (i = 0; i < 6; i++) {
var r = readRadio(i);
if (r) {
if (cntNotes) buildOffsets += ",";
buildOffsets += offsets[r+stringEntry[i]-1];
cntNotes++;
}
}
OutText += "|";
OutText += (cntNotes > 1) ? "Chord" : "Note" ;
OutText += "|Dur:4th|Pos:" ;
OutText += buildOffsets + "\n" ;
OutText += "!NoteWorthyComposerClip-End";
document.nwcform.OutputField.value = OutText;
if (document.nwcform.selAll.checked == true) document.nwcform.OutputField.select();
}
function ChordDisplay(char) {
var str = '<tr>';
str += '<td>'+char+'</td>';
str += '<td><input type="radio" name="S6"></td>';
str += '<td><input type="radio" name="S5"></td>';
str += '<td><input type="radio" name="S4"></td>';
str += '<td><input type="radio" name="S3"></td>';
str += '<td><input type="radio" name="S2"></td>';
str += '<td><input type="radio" name="S1"></td>';
str += '<td>'+char+'</td>';
str += '</tr>';
document.write(str);
}
</script>
</head>
<body onload="startup()">
<form name="nwcform" onsubmit="doChords()">
<table>
<tr>
<td>
<table>
<tr>
<td></td>
<td> E</td>
<td> A</td>
<td> D</td>
<td> G</td>
<td> B</td>
<td> E</td>
</tr>
<script type="text/javascript">
ChordDisplay('X');
ChordDisplay('O');
ChordDisplay('--');
ChordDisplay('--');
ChordDisplay('--');
ChordDisplay('--');
ChordDisplay('--');
ChordDisplay('--');
</script>
</table>
</td>
<td>
<select name="KeyName" id="KeyName"
onChange="setRadio(document.nwcform.KeyName.options[document.nwcform.KeyName.selectedIndex].value);">
<script type="text/javascript">
var ChordPositions = [
"000000,Reset", "013331,A", "013131,A 7", "013321,Am",
"013121,Am7", "013231,AM7", "043121,C", "043421,C 7",
"043111,CM7", "001343,D", "001313,D 7", "001342,Dm",
"001322,Dm7", "001333,DM7", "133211,E", "133111,Em",
"131211,E 7", "131111,Em7", "431114,G", "431112,G7",
];
function Populate(SboxID, ItemArray) {
// empty existing items
for (var i = SboxID.options.length; i >= 0; i--) { SboxID.options[i] = null; }
// add new items
for (var i = 0; i < ItemArray.length; i++) {
tarr = ChordPositions[i].split(',');
SboxID.options[i] = new Option(tarr[1],tarr[0]);
}
// select first item (prompt) for sub list
// SboxID.options[0].selected = true;
}
Populate(KeyName,ChordPositions);
</script>
</select>
</td>
<td>
<table>
<tr>
<td height="27" colspan="8">
<input type="button" id="bClick1" value="Click" onclick="doChords()">
Generated code is to be used on a treble clef shifted down an octave.
</td>
</tr>
<tr>
<td colspan=8 width="1044" height="200">
<textarea name="OutputField" rows="16" cols="120"></textarea>
</td>
</tr>
<tr>
<td>
<input type="checkbox" name=selAll value="ON">Select All
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
<br>
Copy the above to your clipboard and paste it into a song you have already open in <b>NoteWorthy Composer</b>.
<br>If you have opened NWC but haven't opened an existing song or created a new one, <b>Cntrl/Sh V</b>.
<br>
For more information on NWC or to purchase it, click
<a href="http://www.noteworthysoftware.com/">here</a>.
<br> Features or tools in NWC
can change the duration from quarter notes, remove unnecessary sharps or naturals,
and arpeggiate chords (sounds strummed).
<br>Once finished the file can be saved in NWC or midi format.
<br>
<br>
<script>
if (Date.parse(document.lastModified) != 0)
document.write('<p><hr><small><i>Last modified: '
+ document.lastModified
+ '</i></small><br>');
</script>
</body>
</html>
![]() While I know nothing of the 'NWC' system, but looks like to could be modified for other stringed (banjo, ukulele, fiddle or bass [? no frets]) instruments fairly easily. Good Luck!
|
|
#10
|
|||
|
|||
|
Thanks for looking at it, but I couldn't get the pulldown to work.
I have a large songbook with a staff for vocals with the chordnames/fingerings inserted where necessary and wondered how I could transcribe them. If chords are similarly presented for other instruments this might be helpful but if the music is simply presented as notes on a five line staff (one line for percussion), music notation systems such as NWC have been around for years w/o needing to go thru a script like this. My only other NWC script does a twelve tone row, replace "guitar" with "ttr" in link. |
|
#11
|
||||
|
||||
|
OK, sorry about that
... I modified and tested original in FF only. Never got around to MSIE.Drop down should work now as I changed program below to work in FF (PC and Mac) and MSIE. Will test on Safari when I get back to office. Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta name="description" content="Generate guitar chords to be used in NoteWorthy Composer">
<meta name="keywords" content="'guitar chords', noteworthy, composer">
<title>Generate guitar chords</title>
<script language="JavaScript">
function readRadio(i) {
var sel = document.getElementsByName("S"+(6-i));
for (var i=0; i<sel.length; i++) {
if (sel[i].checked == true) return i;
}
}
function setRadio(parm) {
for (var i=0; i < 6; i++) {
var sel = document.getElementsByName("S"+(6-i));
sel[parseInt(parm.charAt(i))].checked = true;
}
}
function startup() {
document.nwcform.selAll.checked = true;
setRadio("000000");
}
function doChords() {
var offsets = [
"n-11", "n-10", "#-10", "n-9", "#-9", "n-8", "#-8", "n-7",
"n-6", "#-6", "n-5", "#-5", "n-4", "n-3", "#-3", "n-2", "#-2", "n-1", "#-1", "n0",
"n1", "#1", "n2", "#2", "n3", "n4", "#4", "n5", "#5", "n6", "#6"
];
var stringEntry = [ 0, 5, 10, 15, 19, 24 ];
var i, j, cntNotes=0, OutText = "", buildOffsets="";
OutText = "!NoteWorthyComposerClip(2.0,Single)\n";
for (i = 0; i < 6; i++) {
var r = readRadio(i);
if (r) {
if (cntNotes) buildOffsets += ",";
buildOffsets += offsets[r+stringEntry[i]-1];
cntNotes++;
}
}
OutText += "|";
OutText += (cntNotes > 1) ? "Chord" : "Note" ;
OutText += "|Dur:4th|Pos:" ;
OutText += buildOffsets + "\n" ;
OutText += "!NoteWorthyComposerClip-End";
document.nwcform.OutputField.value = OutText;
if (document.nwcform.selAll.checked == true) document.nwcform.OutputField.select();
}
function ChordDisplay(char) {
var str = '<tr>';
str += '<td>'+char+'</td>';
str += '<td><input type="radio" name="S6"></td>';
str += '<td><input type="radio" name="S5"></td>';
str += '<td><input type="radio" name="S4"></td>';
str += '<td><input type="radio" name="S3"></td>';
str += '<td><input type="radio" name="S2"></td>';
str += '<td><input type="radio" name="S1"></td>';
str += '<td>'+char+'</td>';
str += '</tr>';
document.write(str);
}
var ChordPositions = [
"000000,Reset", "013331,A", "013131,A 7", "013321,Am",
"013121,Am7", "013231,AM7", "043121,C", "043421,C 7",
"043111,CM7", "001343,D", "001313,D 7", "001342,Dm",
"001322,Dm7", "001333,DM7", "133211,E", "133111,Em",
"131211,E 7", "131111,Em7", "431114,G", "431112,G7",
];
function Populate(IDS,ArrInfo) {
s = document.getElementById(IDS);
var scnt = s.options.length;
for (var i = scnt-1; i >= 0 ; i--) { s.options[i] = null; }
var tmp = [];
for (i = 0; i < ArrInfo.length; i++ ) {
tmp = ArrInfo[i].split(',');
if (tmp[1] == '') { tmp[1] = tmp[0]; }
s.options[s.options.length] = new Option(tmp[1],tmp[0],false,false);
}
}
</script>
</head>
<body onload="startup()">
<form name="nwcform" onsubmit="doChords()">
<table>
<tr>
<td valign="top">
<table>
<tr>
<th></th>
<th>E</th>
<th>A</th>
<th>D</th>
<th>G</th>
<th>B</th>
<th>E</th>
</tr>
<script type="text/javascript">
ChordDisplay('X');
ChordDisplay('O');
ChordDisplay('--');
ChordDisplay('--');
ChordDisplay('--');
ChordDisplay('--');
ChordDisplay('--');
ChordDisplay('--');
</script>
</table>
<br><center>
<select name="KeyName" id="KeyName"
onChange="setRadio(document.nwcform.KeyName.options[document.nwcform.KeyName.selectedIndex].value);">
</center>
<script type="text/javascript">
Populate('KeyName',ChordPositions);
</script>
</select>
</td>
<td>
<table>
<tr>
<td height="27" colspan="8">
<input type="button" id="bClick1" value="Click" onclick="doChords()">
Generated code is to be used on a treble clef shifted down an octave.
</td>
</tr>
<tr>
<td colspan=8 width="900" height="200">
<textarea name="OutputField" rows="16" cols="95"></textarea>
</td>
</tr>
<tr>
<td>
<input type="checkbox" name=selAll value="ON">Select All
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
<br>
Copy the above to your clipboard and paste it into a song you have already open in <b>NoteWorthy Composer</b>.
<br>If you have opened NWC but haven't opened an existing song or created a new one, <b>Cntrl/Sh V</b>.
<br>
For more information on NWC or to purchase it, click
<a href="http://www.noteworthysoftware.com/">here</a>.
<br> Features or tools in NWC
can change the duration from quarter notes, remove unnecessary sharps or naturals,
and arpeggiate chords (sounds strummed).
<br>Once finished the file can be saved in NWC or midi format.
<br>
<br>
<script>
if (Date.parse(document.lastModified) != 0)
document.write('<p><hr><small><i>Last modified: '
+ document.lastModified
+ '</i></small><br>');
</script>
</body>
</html>
|
|
#12
|
|||
|
|||
|
That seems to work in IE--many thanks.
One way it could be modified is to create input for other music notation systems. There is a format called .abc and other well known notation systems are Finale and Sibelius. If they can accept text (and probably write as well) from or to the clipboard, a modification of this script might be helpful. |
|
#13
|
||||
|
||||
|
Post some links and we'll look into it!
|
![]() |
| Bookmarks |
| Tags |
| radio buttons |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|