<HTML>
<HEAD>
<TITLE>Style Numbers</TITLE>
<SCRIPT type=text/javascript>
var myData = new Array(); //– Contains the list entered into the textarea
var myDataDash = new Array(); //– Numbers with dashes listed here
var myDataNoDash = new Array(); //– Numbers without dashes listed here
var txtLine; //– Assigned to each cell of myData as loop runs
var mtCellNoDash=0; //– The mtCellDash and mtCellNoDash variables are used to find
var mtCellDash=0; //– the lowest numbered empty cells in the arrays to avoid creating
//– empty array cells while cycling back and forth between them
function reOrder(){
myData=document.getElementById(“myTextArea”).value.split(‘n’); //–Pulls the data from the textarea
for(i=0;i<=myData.length;i++){
[code=php][code=php]
[/code]
txtLine=myData[i]
if(txtLine==”11-01″ && document.frmOne.chng1101.checked){ //–Changes 11-01 to 1101 if option is checked
myDataNoDash[mtCellNoDash]=”1101″;
mtCellNoDash++;
}else if(txtLine.indexOf(“-“)==-1){
myDataNoDash[mtCellNoDash]=txtLine; //– populating the array with numbers
mtCellNoDash++;
}else{
myDataDash[mtCellDash]=txtLine; //– Populating the array with numbers with dashes
mtCellDash++;
}
}
}
function yesPrint(param){ //– Brings up print dialog when reOrder() completes (IF the option is checked)
if(document.frmOne.goPrint.checked || param == “prntButton”){ //– Print button always brings up print dialog
window.print(document.frmOne.txtOne.value);
}
}
</SCRIPT>
</HEAD>
<BODY>
<FORM name=frmOne><TEXTAREA id=myTextArea name=txtOne rows=22 cols=30>
450
200
458
1457-87
11-01
1101
4589-96
895-78
564
3268-98
2478-51</TEXTAREA>
<br><br>
<INPUT id=”chng1101″ type=”checkbox” checked=”checked” name=”chng1101″>Change 11-01 to 1101<BR>
<INPUT id=”goPrint” type=”checkbox” checked=”checked” name=”goPrint”>Print automatically when sorting is complete<BR><BR>
<INPUT type=”button” value=”Sort” name=”btnOne” onclick=”reOrder()”><BR><BR>
<INPUT onclick=”yesPrint(this.name)” type=”button” value=”Print” name=”prntButton”>
</FORM>
</BODY>
</HTML>
This is a script I’m writing for work. What I’m trying to accomplish here is to take the data entered into the textarea and rearrange it in numerical order. The perfect order would be the numbers with dashes first and then the numbers with no dashes. I haven’t completed it because I can’t seem to get past the If Else part of the reOrder function. I tried to comment everything to explain what I’m trying to do. If I missed anything please let me know.
Thanks