jquery, format

1. How to format currency  - var AmountMax ? The end result should be ($1,000) e.g.
2. How to make TermInYear to convert into INT and then check like below?
if (TermInYear) > 1
label = "Year"
else
label = "Years"?

Thanks,

function parseSelectXMLBondAmountList(xml, selectid, bondState, bondName) {
    var html = "";
    var htmlOption = "";
    var AmountMax = "";
    var AmountMin = "";
    var TermInYear = "";
    $('#' + selectid).prop("disabled", false);   
    $(xml).find('Bond').each(function (i, e) {
        {
            if (bondState == $(e).find('GeneralInformation').find('State').text() && bondName == $(e).find('GeneralInformation').find('Name').text())
            {                 
                var selectedBondName = $(e).find('GeneralInformation').find('Name').text();
                var coverageType = $(e).find('Coverage').attr('Type'); 
                if (coverageType == "list") {
                    $(e).find('Amount').each(function (i, a) {
                        AmountMax = $(a).attr('Max');
                        AmountMin = $(a).attr('Min');
                        TermInYear = $(a).attr('Term');
                        htmlOption += "<option value='" + AmountMax + "'>" + AmountMax + " For " + TermInYear + " Year(s) " + "</option>";
                    });
                }
                else if (coverageType == "range")
                {
                    alert("Range");
                    htmlOption += "";
                    AmountMax = $(e).find('Amount').attr('Max');
                    AmountMin = $(e).find('Amount').attr('Min');                   
                }
                else
                {
                    AmountMax = $(e).find('Amount').attr('Max');
                    AmountMin = $(e).find('Amount').attr('Min');                                      
                }
            }
        }
    });   
    $("#" + selectid).html(htmlOption);
    //$("#test1").append("<select>" + htmlOption + "</select>");
}

Open in new window

LVL 1
ITsolutionWizardAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ITsolutionWizardAuthor Commented:
any helps?
0
ITsolutionWizardAuthor Commented:
any helps?
0
ITsolutionWizardAuthor Commented:
Any helps?
0
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

ITsolutionWizardAuthor Commented:
no one can help?
0
Ioannis ParaskevopoulosCommented:
Hi,

About your first question you may check this question.

About your second question, you could just check if TermInYear equals "1".

if (TermInYear == '1') {
    label = "Year";
} else {
    label = "Years";
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Julian HansenCommented:
To convert to an int put a + sign in front of the value
var label = (+TerminYear > 1) ? 'Years' : 'Year';

Open in new window


You can format your currency like this
<script>
String.prototype.format = function (cur) {
	var x = this;
	var t = '';
	for(var i = x.length - 1; i >= 0; i--) {
		t = ((x.length-i)%3==0?',':'') + x[i] + t;
	}
	t = (t[0] == ',') ? t.substr(1) : t;
	return cur + t
}
var x = '100000';
console.log(x.format('$'));

</script>

Open in new window

0
ITsolutionWizardAuthor Commented:
the format is not working
0
Julian HansenCommented:
That is not useful - you need to show us how you implemented it and what results you got "It is not working" simply does not give us enough information to proceed.

... and yes the code does work please see this sample
http://www.marcorpsa.com/ee/t2798.html
0
ITsolutionWizardAuthor Commented:
AmountMax = $(a).attr('Max').format('$');

I have above codes and it is not working
0
Julian HansenCommented:
Last chance then I am quitting.

To solve your problem we need to see inputs and outputs. I really want to help you but if you are not going to come to the party then I will focus on other questions.
1
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.