This discussion is archived
10 Replies Latest reply: Dec 5, 2012 10:08 PM by Prabodh RSS

Validate Apex_Item using Javascript

Sudhir_Meru Newbie
Currently Being Moderated
Hi,

Below query has two text box, When the two text box is null and user clicks on the button it must alter the user saying enter value.

SELECT
apex_item.text(1, NULL, 4, 4, NULL, 'f01_#ROWNUM#') ONE,
apex_item.text(2, NULL, 4, 4, NULL , 'f02_#ROWNUM#') TWO
FROM DUAL


I tried the below code using java script but this is not working,
<script type="text/javascript">
function port(pRow) {
var txb = $x_Item('f01_'+pRow); // I don't know which syntax is this!
if ( txb.value == '' ) {
alert('Enter value in first box');
txb.style.backgroundColor = '#a00';
}
else{
txb.style.backgroundColor = ''; //return to default color
}
}
</script>
The above script i wrote only for first text box, Please suggest me to modify the code.

Thanks
Sudhir
  • 1. Re: Validate Apex_Item using Javascript
    Prabodh Guru
    Currently Being Moderated
    Apex version?
    If on 4.x use DA, it will be much simpler.
    If older, where are you calling the JS function port(pRow) ? Which event? Post that code ,too.
    Cheers,
  • 2. Re: Validate Apex_Item using Javascript
    Sudhir_Meru Newbie
    Currently Being Moderated
    I am using Apex 3.2, This is a manual tabular form. I have posted both the code in first post sql and javascript.


    I am calling the function on the button click


    Please suggest me if there is any alternative method if available.


    Thanks
    Sudhir
  • 3. Re: Validate Apex_Item using Javascript
    Prabodh Guru
    Currently Being Moderated
    I am using Apex 3.2, This is a manual tabular form. I have posted both the code in first post sql and javascript.
    I am calling the function on the button click

    Please suggest me if there is any alternative method if available. >

    Tabular form means multiple rows. The alert should come only once for the page or for each occurrence of null value?

    Cheers,
  • 4. Re: Validate Apex_Item using Javascript
    Prabodh Guru
    Currently Being Moderated
    Try this
    <script type="text/javascript">
    function port() {
      var txb = document.getElementsByName('f01');
      var null_found boolean = false;
      for (i=0; i< txb.length;i++) {
          if ($v(txb.id)) {
    txb[i].style.backgroundColor = ''; //return to default color
    } else {
    txb[i].style.backgroundColor = '#a00';
    null_found = true;
    }
    }
    if (null_found ) {
    alert('Enter value in first box');
    }
    }
    </script>
    Cheers,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
  • 5. Re: Validate Apex_Item using Javascript
    VC Guru
    Currently Being Moderated
    Sudhir_Meru wrote:
    I am using Apex 3.2, This is a manual tabular form. I have posted both the code in first post sql and javascript.


    I am calling the function on the button click


    Please suggest me if there is any alternative method if available.


    Thanks
    Sudhir
    You have to loop through and highlight the row that was not filled

    If you are using jQuery try
    $('.notnull').remove();
    //replace f01 with your column names
    $('input[name="f01"]').each(function (index) {
         if (this.value == '') {
              $(this).parent().append('<div class="notnull" style="color:red;">This must have some value</div>');
         }
    });
    Edited by: VC on Dec 5, 2012 1:11 PM
  • 6. Re: Validate Apex_Item using Javascript
    Prabodh Guru
    Currently Being Moderated
    AFAIK, Apex 3.2 did not have jQuery built-in. You had to include it if you wanted to use it.
    Anyway, I do not have a 3.2 instance anymore. This is more out of memory.

    Cheers.
  • 7. Re: Validate Apex_Item using Javascript
    Sudhir_Meru Newbie
    Currently Being Moderated
  • 8. Re: Validate Apex_Item using Javascript
    Prabodh Guru
    Currently Being Moderated
    It is a snippet that I wrote for your query.
    If you cannot spot the differences then its your issue.
  • 9. Re: Validate Apex_Item using Javascript
    Sudhir_Meru Newbie
    Currently Being Moderated
    Got the soloution below. I Fixed Got the solution. Spot the difference It was my mistake

    <script>
    function nullcheck()
    {
    var v = document.getElementById('f01');
    if(document.getElementById('f01').value=="")
    {
    alert("Please enter value.");
    v.style.backgroundColor = "red";
    return false;
    }
    else
    {
    v.style.backgroundColor = "white";
    }
    }
    </script>

    Thanks For Suggestion
  • 10. Re: Validate Apex_Item using Javascript
    Prabodh Guru
    Currently Being Moderated
    First you say it is a tabular forms. And now you say it works with
    var v = document.getElementById('f01');
    Strange. The above should not return any elements because there should be no id=f01 in tabular form.

    Cheers,

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points