views:

19

answers:

1

I am trying to make some fields mandatory for creating a bug in Bugzilla, from what I have read, the easiest way is by using JavaScript. The code I have used is shown below but doesnt seem to be working. My Javascript knowledge is pretty limited so i am presuming it is an error in my coding.

        <script type="text/javascript">
        <!--
            function mandatory_text_check(){
               if (this.form.short_desc.value == '')
               {
               alert('Please enter a summary sentence for this [% terms.bug %].');
               return false;
               }
               else if (this.form.estimated_time.value == '0.0' && this.form.cf_issuetype.value == 'Task')
               {
               alert('Please enter an estimated time for completion of this task.');
               return false;
               }
               else
               return true;
            }
        -->
        </script>



// Function is called from the commit button on the bottom of the page


      <input type="submit" id="commit" value="Commit"
             onclick="mandatory_text_check();">
A: 

I believe the problem is this line:

if (this.form.short_desc.value == '')

and all other places where you use this. Try document instead.

It would be a big help if you include the FORM markup (or a sample if its big) as that is relevant.

michael
Yea, the problem was partly there, i replaced this.form with document.create. This is defined earlier in the code ( var form = document.Create;) but didnt seem to be recognised. I also had to create a variable for the function to return true or false and add this to the onclick <input type="submit" id="commit" value="Commit"onclick="mandatory_text_check();return ret;">Working perfectly now, thanks for your help