Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

javascript parameters returning float

  • 09-01-2005 7:05pm
    #1
    Registered Users, Registered Users 2 Posts: 884 ✭✭✭


    Can anyone find anything wrong with this ??
    function gpv(gpvval)
    	{
    		alert ("this is gpvval ... " + gpvval + "")
    		if (gpvval > 100)
    		{
    		gpvval = 'N/A';
    		}
    		if (gpvval <= 100 && gpvval >= 80)
    		{
    		gpvval = parseFloat(4.0);
    		}
    		if (gpvval <= 79 && gpvval >= 70)
    		{
    		gpvval = '3.5';
    		}
    		if (gpvval <= 69 && gpvval >= 60)
    		{
    		gpvval = 3.0;
    		}
    		if (gpvval <= 59 && gpvval >= 55)
    		{
    		gpvval = 2.5;
    		}
    		if (gpvval <= 54 && gpvval >= 50)
    		{
    		gpvval = 2.0;
    		}
    		if (gpvval <= 49 && gpvval >= 40)
    		{
    		gpvval = 1.5;
    		}
    		if (gpvval <= 39 && gpvval >= 35)
    		{
    		gpvval = 1.0;
    		}
    		if (gpvval <= 38 && gpvval >= 0)
    		{
    		gpvval = 0;
    		}
    		return gpvval;
    		}
    

    Anything above 100 works but everthing else is just 0 ??

    Any ideas ??


Comments

  • Closed Accounts Posts: 4,655 ✭✭✭Ph3n0m


    after using the if for your first statement, use else if's


  • Registered Users, Registered Users 2 Posts: 884 ✭✭✭Cork Skate


    Ph3n0m wrote:
    after using the if for your first statement, use else if's

    Nah ... tried that ... doesn't work !!

    I am thinking that it is trying to change gpvval to a float that is doing it.
    if i change all the other values to 'L/N' or 'Ted' or whatever it works fine ... so it must be the format.

    gpvval comes from the main code parseFloat(document.form.textfield.value) so i would have thought there'd be no problem when it was pass into the function but obviously there is ... even when i enter a float i.e. 85.21 it goes straight to 0 ..... i need to be able to pass a float back down to when the function is called.

    Anyone know how to do this ??


  • Registered Users, Registered Users 2 Posts: 884 ✭✭✭Cork Skate


    function gpv(gpvval) {
    		var gpa = 0;
    		if (gpvval > 100) {
    			gpa = 'N/A';
    		} else if (gpvval >= 80) {
    			gpa = '4.0';
    		} else if (gpvval >= 70) {
    			gpa = '3.5';
    		} else if (gpvval >= 60) {
    			gpa = '3.0';
    		} else if (gpvval >= 55) 	{
    			gpa = '2.5';
    		} else if (gpvval >= 50) {
    			gpa = '2.0';
    		} else if (gpvval >= 40) {
    			gpa = '1.5';
    		} else if (gpvval >= 35) {
    			gpa = '1.0';
    		} else if (gpvval >= 0) {
    			gpa = '0';
    		}
    		return gpa;
    	}
    

    This is the one that works .... i dont know what else i did but its all good now !!


Advertisement