10 Replies Latest reply on May 27, 2012 2:09 PM by xarg-Xrc

    Facing problem with javascript code in URL

    665735
      Hi All,

      I am uisng button template as "Button" and button style as Template based button and i am trying to call javascript under
      Optional URL Redirect by selecting URL as

      javascript:"return checkFiles(this)";

      but that is not wroking? Any idea how to resolve this issue.

      Thanks,
      Anoo..
        • 1. Re: Facing problem with javascript code in URL
          fac586
          Anoo wrote:

          I am uisng button template as "Button" and button style as Template based button and i am trying to call javascript under
          Optional URL Redirect by selecting URL as

          javascript:"return checkFiles(this)";

          but that is not wroking? Any idea how to resolve this issue.
          Remove the double quotes.

          Use a decent browser with a JavaScript console and debugger like Safari, Chrome or Firefox+Firebug to troubleshoot JS issues.

          Learn some basic JavaScript.
          • 2. Re: Facing problem with javascript code in URL
            665735
            Hi,

            I have tried both of ways but it throwing error as return not in function.

            javascript:return checkFiles();

            function checkFiles(){
            alert('Hello');
            return;
            }

            But it is not wroking, cna you let me know where i have doen wrong.

            Thanks,
            Anoo..
            • 3. Re: Facing problem with javascript code in URL
              Jozef Demovic SVK
              hi,

              Try javascript: alert('test');
              It must works .... otherwise try to reproduce your problem on apex.oracle.com

              Regards
              J :D
              • 4. Re: Facing problem with javascript code in URL
                Recx Ltd
                Anoo wrote:
                I have tried both of ways but it throwing error as return not in function.

                javascript:return checkFiles();

                function checkFiles(){
                alert('Hello');
                return;
                }
                'return' should only be used in functions, the line should be;

                javascript:checkFiles();
                • 5. Re: Facing problem with javascript code in URL
                  fac586
                  Anoo wrote:
                  Hi,

                  I have tried both of ways but it throwing error as return not in function.

                  javascript:return checkFiles();
                  Why do you have <tt>return</tt> here?

                  What happens with:
                  javascript: checkFiles();
                  ???
                  function checkFiles(){
                  alert('Hello');
                  return;
                  }

                  But it is not wroking, cna you let me know where i have doen wrong.
                  From this? No.

                  Reproduce on apex.oracle.com.
                  • 6. Re: Facing problem with javascript code in URL
                    665735
                    Hi,

                    I have made changes to script by removing the return, now i ma trying to call this function checking while uploding the files dwuplicate files shoudl not exists.
                    Can you please help me how do we can have javascript validation for this?

                    Here i have done but it is not identfying the elements.lenght object.

                    javascript: checkFiles();

                    <script type="text/javascript">
                    function checkFiles(frm) {
                    var filenames = ';';
                    for (i=0;i<frm.elements.length;i++) {
                    if (frm.elements.type=='file') {
                    if (filenames.indexOf(';'+frm.elements[i].value+';') == -1) {
                    filenames += frm.elements[i].value+';';
                    } else {
                    alert('filenames cannot match');
                    return false;
                    }
                    }
                    }
                    return true;
                    }


                    Thanks,
                    Anoo..
                    • 7. Re: Facing problem with javascript code in URL
                      VC
                      Anoo wrote:
                      Hi,

                      I have made changes to script by removing the return, now i ma trying to call this function checking while uploding the files dwuplicate files shoudl not exists.
                      Can you please help me how do we can have javascript validation for this?

                      Here i have done but it is not identfying the elements.lenght object.
                      Where is this elements coming from?
                      what is frm?
                      Are you sending the correct value into parameter frm?


                      *Always include code in {noformat}{noformat} tags, otherwise it is not readable*
                      javascript: checkFiles();

                      <script type="text/javascript">
                      function checkFiles(frm) {
                      var filenames = ';';
                      for (i=0;i<frm.elements.length;i++) {
                      if (frm.elements.type=='file') {
                      if (filenames.indexOf(';'+frm.elements[i].value+';') == -1) {
                      filenames += frm.elements[i].value+';';
                      } else {
                      alert('filenames cannot match');
                      return false;
                      }
                      }
                      }
                      return true;
                      }
                      • 8. Re: Facing problem with javascript code in URL
                        665735
                        Hi VC,

                        I have modifed the script code which is wroking now!! but an issue with mine return value.
                        When i say return false or return true it is redirecting to page like popup page, i mean not exactly popupage i do not what term to be used to tell you that page.

                        My idea is when both are same then i am displaying error alert messsage and it should stops the process which is fine when i have keep return insted of return false in my new javascript code.

                        But when i keep return true it should procees how i can achieve this.? If i keep return true that is not wroking i mean going to browser page
                        .

                        How can resolve this?

                        Start Code--{

                        <script type="text/javascript">

                        function checkFiles()
                        {
                        var arrfilenames = new Array();
                        var s= 0;
                        for (var i=0, j=wwvFlowForm.elements.length; i<j; i++)
                        {
                        myType = wwvFlowForm.elements.type;
                        if (myType == 'file' && wwvFlowForm.elements[i].value !='')
                        {
                        arrfilenames[s]= wwvFlowForm.elements[i].value;
                        s++;
                        }
                        }
                        //alert(arrfilenames.length);
                        for(var p=0;p<arrfilenames.length; p++){
                        alert("p val isss-->"+arrfilenames[p]);
                        }
                        for(var m=0;m < arrfilenames.length; m++)
                        {

                        for( var l = m +1;l<arrfilenames.length;l++)

                        {
                        // alert("arrfilenames[m]"+arrfilenames[m]);
                        // alert("arrfilenames[l]"+arrfilenames[l]);
                        if (arrfilenames[m] == arrfilenames[l])
                        {
                        alert('Duplicate file names' + ' ' + arrfilenames[l]);
                        return;
                        }

                        }
                        }
                        return;
                        }

                        --Code End }

                        Thanks,
                        Anoo.
                        • 9. Re: Facing problem with javascript code in URL
                          xarg-Xrc
                          Have you run your code through a Javascript debugger? IE has one (hit F12 to fire it up) and you can use firebug in Chrome/Firefox.

                          From past experience, It's very hard to pin point problem by simply looking at mountain of code here.

                          I ran into Javascript/Ajax issue before and posted here and elsewhere and got no where. Turns out issue was with the type of Double-quote which my text-editor was putting in which was causing problem. I figured that out after I figured out how to debug.
                          • 10. Re: Facing problem with javascript code in URL
                            xarg-Xrc
                            This is how you debug (using Internet Explorer)

                            http://i.imgur.com/ABVmi.png
                            1 person found this helpful