what am I doing wrong here?. I have a number field which I'm trying to validate if its greater than 0

  • 0
  • 1
  • Question
  • Updated 4 years ago
  • Answered

var numberOfRates = $("#_fid_98");

if (  numberOfRates > 0 &&  $("#_fid_351").prop("checked") == false ) {
    alert (">>>>>>>>>>>>>>>>>>");

fid_98 is of type number



Photo of Tribs

Tribs

  • 20 Points

Posted 4 years ago

  • 0
  • 1
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,044 Points 20k badge 2x thumb
Your statement below is returning the jQuery wrapped form element with id=_fid_98

var numberOfRates = $("#_fid_98");

If you want to value of the form element with id=_fid_98 you have to call the val() method:
var numberOfRates = $("#_fid_98").val();
The above statements use jQuery. But you can use pure JavaScript to access the value of the form element with id=_fid_98 as follows:
var numberOfRates = document.getElementById("_fid_98").value
What may surprise even seasoned developers that you can also access the form element with id=_fid_98 with pure JavaScript as follows:
var numberOfRates = _fid_98.value
This is because all modern browsers create Global Variables named after the value of id attribute on any element.
You should experiment with partially filling out your form and then typing these statements into the JavaScript Console..
Photo of Tribs

Tribs

  • 20 Points
I tried all the methods .val() etc, but the value is blank. I'm using the Image onload technique and moved the load feature to the bottom of the form. is this script getting executed before the form is fully loaded?.
Photo of Tribs

Tribs

  • 20 Points
ok.. for text fields I was able to get the value with this method _fid_98.value , for number (summary) or number (formula) it is not working. any pointers?
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,044 Points 20k badge 2x thumb
>for number (summary) or number (formula) it is not working. any pointers?

Summary and Formula fields are not inputs so there is no form control used to enter the value. Without a form control there is no name or id based selector to conveniently grab the value. I am sure there is an alternate selector to grab the summary or formula field but it will depend on the exact construction of your form / summary report.