• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 55
  • Last Modified:

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

0
ITsolutionWizard
Asked:
ITsolutionWizard
  • 6
  • 3
1 Solution
 
ITsolutionWizardAuthor Commented:
any helps?
0
 
ITsolutionWizardAuthor Commented:
any helps?
0
 
ITsolutionWizardAuthor Commented:
Any helps?
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now