11 Replies - 3129 Views - Last Post: 19 July 2013 - 03:21 PM

#1 TacoJeebus   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 25-April 12

Converting Hidden Text Field to Numerical Value

Posted 19 July 2013 - 06:40 AM

I have this bit of code, it's supposed to take the value from one field, and calculate the value from it based on a certain percentage (in this case 60%).

I created a hidden field to store the value in the html, but when I run the calculation and check it in Firebug it gets a NaN value. Can anyone tell me what I can do to produce the number I need?

f (Apply_RequestedAmtX_r != 0 & Apply_RequestedAdvanceAmtY_r !=0){
    var AmtX= ($('#Apply_RequestedAdvanceAmtX_r').val());
    var AmtY= ($("#Apply_AmtYAfterSplit_r").val());
    var MaxAMT = parseInt((AmtY*60)/100);
    $('#mna').val(MaxAMT);



Is This A Good Question/Topic? 0
  • +

Replies To: Converting Hidden Text Field to Numerical Value

#2 laytonsdad   User is offline

  • I identify as an attack helicopter!
  • member icon

Reputation: 467
  • View blog
  • Posts: 1,998
  • Joined: 30-April 10

Re: Converting Hidden Text Field to Numerical Value

Posted 19 July 2013 - 10:47 AM

First off & is not equal to &&,

you also haven't given all the relevant code.
Was This Post Helpful? 0
  • +
  • -

#3 TacoJeebus   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 25-April 12

Re: Converting Hidden Text Field to Numerical Value

Posted 19 July 2013 - 11:41 AM

if (Apply_RequestedAdvanceAmtX_r != 0 && Apply_RequestedAdvanceAmtY_r !=0){
    var amtX = parseInt($('#Apply_RequestedAdvanceamtX _r').val());
    var amtY = parseInt($("#Apply_amtYAfterSplit_r").val());
    var MaxAMT = Math.round((amtY*60)/100);
    $("#MaxAMT").val($("#mnax").val());
	
         if(amtX > amtY) {
	
		  $("#Apply_RequestedAdvanceamtY_r").val($("#MaxAMT").val()); 
          alert(Amount Exceeded.');
		  
          return false;
        }

    return true;

}

		}



I couldn't find an edit button, but it's like yesterday, but with some variations. I got that working, and then I made some changes, now one of the fields blank out when I run the code.

This post has been edited by Dormilich: 20 July 2013 - 01:41 AM

Was This Post Helpful? 0
  • +
  • -

#4 laytonsdad   User is offline

  • I identify as an attack helicopter!
  • member icon

Reputation: 467
  • View blog
  • Posts: 1,998
  • Joined: 30-April 10

Re: Converting Hidden Text Field to Numerical Value

Posted 19 July 2013 - 11:48 AM

Which field "blanks out"
Was This Post Helpful? 0
  • +
  • -

#5 TacoJeebus   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 25-April 12

Re: Converting Hidden Text Field to Numerical Value

Posted 19 July 2013 - 11:49 AM

Amt Y.
Was This Post Helpful? 0
  • +
  • -

#6 TacoJeebus   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 25-April 12

Re: Converting Hidden Text Field to Numerical Value

Posted 19 July 2013 - 11:54 AM

Let me break this down,

User enters amount in Amt X. It automatically calculates 60% of amount x no matter what.

If the user then enters a number in amount Y that is in excess of Amount X it is supposed to replace the number in Amount X with the number created by the calculation aka maxAMT.
Was This Post Helpful? 0
  • +
  • -

#7 laytonsdad   User is offline

  • I identify as an attack helicopter!
  • member icon

Reputation: 467
  • View blog
  • Posts: 1,998
  • Joined: 30-April 10

Re: Converting Hidden Text Field to Numerical Value

Posted 19 July 2013 - 12:19 PM

Try this

 if (Apply_RequestedAdvanceAmtX_r != 0 && Apply_RequestedAdvanceAmtY_r != 0) {
        var amtX = parseInt($('#Apply_RequestedAdvanceamtX _r').val());
        var amtY = parseInt($("#Apply_amtYAfterSplit_r").val());
        var MaxAMT = Math.round((amtY * 60) / 100);
        $("#MaxAMT").val($("#mnax").val());

        if (amtX > amtY) {

            $("#Apply_RequestedAdvanceamtY_r").val($("#MaxAMT").val());
            alert('Amount Exceeded.');
        }
    }



I removed the returns as it is not a function, and there was an extra bracket
Was This Post Helpful? 0
  • +
  • -

#8 TacoJeebus   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 25-April 12

Re: Converting Hidden Text Field to Numerical Value

Posted 19 July 2013 - 12:36 PM

It actually is a function, I didn't paste that part in.

I also added this to catch the information for the hidden field.

var mnaField = parseInt($("#mnax").val());



Of course, this field is now pulling an NaN value.
Was This Post Helpful? 0
  • +
  • -

#9 laytonsdad   User is offline

  • I identify as an attack helicopter!
  • member icon

Reputation: 467
  • View blog
  • Posts: 1,998
  • Joined: 30-April 10

Re: Converting Hidden Text Field to Numerical Value

Posted 19 July 2013 - 12:37 PM

So when I posted this you only posted the same code again.

View Postlaytonsdad, on 19 July 2013 - 05:47 PM, said:

you also haven't given all the relevant code.

Was This Post Helpful? 0
  • +
  • -

#10 TacoJeebus   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 25-April 12

Re: Converting Hidden Text Field to Numerical Value

Posted 19 July 2013 - 12:40 PM

No, I didn't I added about double the code, and added what I thought was relevant. I forgot about the function line up top, but that is it.

This post has been edited by Dormilich: 20 July 2013 - 01:41 AM

Was This Post Helpful? 0
  • +
  • -

#11 TacoJeebus   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 25-April 12

Re: Converting Hidden Text Field to Numerical Value

Posted 19 July 2013 - 12:55 PM

Here is what I'm trying now, even more code, with the function included...

function CheckMaxAmount(){
			
    

if (Apply_RequestedAdvanceAmtX_r != 0 && Apply_RequestedAdvanceAmtY_r !=0){
	$("#MaxAMT").val($("#mnax_r").val());
    var AmtY = parseInt($('#Apply_RequestedAdvanceAmtY_r').val());
    var AmtX= parseInt($("#Apply_AmtXAfterSplit_r").val());
	var MaxAMT = Math.round((AmtX*60)/100);
	$("#mnax_r").val($("#MaxAMT").val()); 
	var mnaField = parseInt($("#mnax_r").val());
	      
    
	
         if(AmtY > AmtX) {
	
		  $("#Apply_RequestedAdvanceAmtY_r").val($("#mnax_r").val()); 
          alert('Your advance cannot exceed your commission.');
		  
          return false;
        }

    return true;

}

		}



This post has been edited by laytonsdad: 19 July 2013 - 03:11 PM
Reason for edit:: removed bold tags

Was This Post Helpful? 0
  • +
  • -

#12 laytonsdad   User is offline

  • I identify as an attack helicopter!
  • member icon

Reputation: 467
  • View blog
  • Posts: 1,998
  • Joined: 30-April 10

Re: Converting Hidden Text Field to Numerical Value

Posted 19 July 2013 - 03:21 PM

What are these in your if statement, and how do they get passed into the function?

Apply_RequestedAdvanceAmtX_r

Apply_RequestedAdvanceAmtY_r
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1