Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

asked on

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

Avatar of ITsolutionWizard
ITsolutionWizard
Flag of United States of America image

ASKER

any helps?
any helps?
Any helps?
no one can help?
ASKER CERTIFIED SOLUTION
Avatar of Ioannis Paraskevopoulos
Ioannis Paraskevopoulos
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

the format is not working
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
AmountMax = $(a).attr('Max').format('$');

I have above codes and it is not working
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.