/    Sign up×
Community /Pin to ProfileBookmark

If Else help

<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]

[/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

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@TaleYkauthorDec 25.2010 — Please ignore the PHP code. I can't figure out how to remove it
×

Success!

Help @TaleYk 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 5.10,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...