Problem with Error: Expected ')'...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • viki1967
    Contributor
    • Oct 2007
    • 263

    Problem with Error: Expected ')'...

    Hi all.

    I have problem with this string javascript:

    Code:
    onclick="if(confirm('Confirm?')) location.href('form.asp?A=terry.d'arby'); return false;
    The error javascript is:
    Error: Expected ')'

    Why? Can you help me?
    Kind regards
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Originally posted by viki1967
    Can you help me?
    sure, your url string is invalid, you have alltogether 5 unescaped ' in your line (is that 2 and a half strings?), thus the last ) is part of a string.

    Comment

    • viki1967
      Contributor
      • Oct 2007
      • 263

      #3
      Originally posted by Dormilich
      sure, your url string is invalid, you have alltogether 5 unescaped ' in your line (is that 2 and a half strings?), thus the last ) is part of a string.
      When resolve my problem?
      thanks

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        Originally posted by viki1967
        When resolve my problem?
        as soon as you can.

        you have four options (I know of)
        • use the typographical apostrophe (U+2019)
        • use encodeURI()
        • nest the string (use " and ')
        • escape the non-delimiter '

        Comment

        • viki1967
          Contributor
          • Oct 2007
          • 263

          #5
          thanks, but I try this and not working...

          Code:
          onclick="if(confirm('Confirm?')) location.href('Form.asp?A=' + encodeURIComponent(terry.d'arby) + '); return false;

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            well, you have 5 unescaped and 1 escaped ' (similar situation like before)

            Comment

            • viki1967
              Contributor
              • Oct 2007
              • 263

              #7
              Originally posted by Dormilich
              well, you have 5 unescaped and 1 escaped ' (similar situation like before)
              I don't understand.. sorry...

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                hm, not sure how the return string of encodeURICompon ent is treated.
                Originally posted by MDC
                encodeURICompon ent escapes all characters except the following: alphabetic, decimal digits, - _ . ! ~ * ' ( )
                what about
                Code:
                onclick="if(confirm('Confirm?')) location.href('Form.asp?A=' + encodeURIComponent(terry.d'arby)[U] + '[/U]); return false;
                Last edited by Dormilich; Sep 10 '09, 09:08 AM. Reason: added 5th ' code

                Comment

                • viki1967
                  Contributor
                  • Oct 2007
                  • 263

                  #9
                  Originally posted by Dormilich
                  hm, not sure how the return string of encodeURICompon ent is treated.
                  Not working:

                  Code:
                  onclick="if(confirm('Confirm?')) location.href('Form.asp?A=' + encodeURI(terry.d'arby) + '); return false;
                  Not working:
                  Code:
                  onclick="if(confirm('Confirm?')) location.href('Form.asp?A=encodeURI(terry.d'arby)); return false;

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #10
                    think of what you wrote there.

                    Code:
                    onclick="if(confirm('Confirm?')) location.href('Form.asp?A=' + encodeURI(terry.d'arby)[U] + '[/U]); return false;

                    Code:
                    onclick="if(confirm('Confirm?')) location.href([U]'Form.asp?A=encodeURI(terry.d'[/U]arby)); return false;

                    Comment

                    • Dormilich
                      Recognized Expert Expert
                      • Aug 2008
                      • 8694

                      #11
                      something that just popped to my attention:
                      Code:
                      location.href = new_URI;
                      // not
                      location.href(new_URI);
                      at least that’s what’s defined in the specs

                      Comment

                      • viki1967
                        Contributor
                        • Oct 2007
                        • 263

                        #12
                        Nothing...

                        Code:
                        onclick="if(confirm('Sure?')) location.href = 'Form.asp?A='+encodeURI(terry.d'arby)+''; return false;

                        Comment

                        • Dormilich
                          Recognized Expert Expert
                          • Aug 2008
                          • 8694

                          #13
                          any error messages?


                          Comment

                          • viki1967
                            Contributor
                            • Oct 2007
                            • 263

                            #14
                            Originally posted by Dormilich
                            any error messages?

                            Error: Expected ')' :(

                            Comment

                            • Dormilich
                              Recognized Expert Expert
                              • Aug 2008
                              • 8694

                              #15
                              use one of the other two possibilities mentioned earlier.

                              Comment

                              Working...