PDA

View Full Version : functions.Ineed help and guidance



steve.d
Mar 8th, 2007, 09:36 PM
Is their anyone that can help me, i am new to java script, and need help or at least setting in the right direction with the following program.
<title>Process tax codes</title>

<script language="JavaScript" >

var taxNumberData = ['10P7-TXL/19P8777','32-TCM/2456OC','756-SPK/405P11','732-TCZ/0P987'];
var taxNumber = '';

// ----Get taxCode

taxNumber = taxNumberData[0];
for (count = 0; count <= taxNumber.length; count = count + 1)
{

};
document.write('<BR>' + 'Tax number is ' + taxNumber + '<BR>')

Question is
How do i set this program to use the first letter and the last letter between the -and the / to put each of the four tax numbers in to diferent tax brackets.if some one could point me in the right direction please

steve.d
:confused:

chump2877
Mar 9th, 2007, 02:31 AM
If you;re just trying to isolate the 3 character tax code for each tax data array element, use regular expressions:


<script language="JavaScript" >

var taxNumberData = ['10P7-TXL/19P8777','32-TCM/2456OC','756-SPK/405P11','732-TCZ/0P987'];
var matches = new Array;
var myRegExp = /(.+?)(-)(.+?)(\/)(.+?)/;

for (i=0; i<taxNumberData.length; i++)
{
matches = taxNumberData[i].match(myRegExp);
alert("Tax code for '"+taxNumberData[i]+"' is '"+matches[3]+"'");
matches.length = 0;
}

</script>

steve.d
Mar 9th, 2007, 06:30 AM
If you;re just trying to isolate the 3 character tax code for each tax data array element, use regular expressions:


<script language="JavaScript" >

var taxNumberData = ['10P7-TXL/19P8777','32-TCM/2456OC','756-SPK/405P11','732-TCZ/0P987'];
var matches = new Array;
var myRegExp = /(.+?)(-)(.+?)(\/)(.+?)/;

for (i=0; i<taxNumberData.length; i++)
{
matches = taxNumberData[i].match(myRegExp);
alert("Tax code for '"+taxNumberData[i]+"' is '"+matches[3]+"'");
matches.length = 0;
}

</script>
Thanks i'll try that at least it puts me on the right track
steve.d

Philip M
Mar 9th, 2007, 07:30 AM
A search would have directed you to:-

http://www.codingforums.com/showthread.php?t=108876