• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1166
  • Last Modified:

javascript missing : after property id

Hello,
I am trying to pass the string below as an argument to a javascript funtion generated when the user clicks on an icon.

The string I am trying to pass is:  {Mallard=3_Duckling,5_Juvenile,8_Adult}{Mallard=M,F}{Mallard=23_Ringtail/Redhead,24_Eclipse}

I am getting the error 'missing : after property id' and can't get my string to pass as it should.
Is this a problem with the curly brackets ? Is there any way of getting round it ?

any ideas ?

Thanks
// Workaround for IE bug
    if ((document.all) && (document.getElementById))
    {
        tinyPlusSubrowImage['onclick'] = new   Function('test(' + ageSexPhaseString+')');
    }
    else
    { // FireFox
        tinyPlusSubrowImage.setAttribute('onclick','test(' + ageSexPhaseString + ')');
    }

Open in new window

0
COMPSUPP
Asked:
COMPSUPP
  • 6
  • 5
1 Solution
 
HonorGodSoftware EngineerCommented:
in the THEN clause, you probably want to use something like:
tinyPlusSubrowImage['onclick'] = new function( test( ageSexPhaseString ) }

Open in new window

0
 
COMPSUPPAuthor Commented:
By the THEN clause, do you mean else ?

If I need to replace the curly brackets with something else, do I need slashes in the replace as they are special characters ?
0
 
HonorGodSoftware EngineerCommented:
No, I mean the then clause.


Currently, you have it looking like:

tinyPlusSubrowImage['onclick'] = new   Function('test(' + ageSexPhaseString+')');

Problems:
- Javascript is case sensitive, so "new Function" isn't correct, it should be function
- After you make that change, it would look like:
  ... = new function('test(' + ageSexPhaseString+')')

  Is it your intension to pass the string (something like this) to the new anonymous function?

  test( ageSexPhaseString )
    if ( expression )
    {
        // Then clause
    }
    else
    { 
       // Else clause
    }

Open in new window

0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
COMPSUPPAuthor Commented:
Thanks for that - might help with IE - my expression is to see if the browser is IE or Firefox.

I still have a problem in the else clause (which it uses when the browser is FireFox) trying to pass the string to the new anon function. I think this problem may be that there are curly brackets and commas in the string I am passing. I don't know if I can use escape characters or something to somehow get around this.
0
 
HonorGodSoftware EngineerCommented:
Having "browser detect" code is rarely a good thing.

Generally, it is better to have "object detect" code.
For example:

http://www.quirksmode.org/js/detect.html
0
 
COMPSUPPAuthor Commented:
Yes, I thought object detect code was what I was using with:

if ((document.all) && (document.getElementById))
    {
    }else{
}
0
 
HonorGodSoftware EngineerCommented:
Yes, I just tend to jump on the phrase "browser detect". :-)  Sorry about that.
0
 
COMPSUPPAuthor Commented:
Right, I have got rid of the : error by removing the starting curly brackets and replacing the closing curly brackets with double colons like this:

Guillemot=5_Juvenile,6_Immature,8_Adult::Guillemot=M,F::Guillemot=21_Bridled,22_Unbridled::

I need something to distinguish between the sections in the string, so that's why I cant get rid of the curly brackets and not replace them at all.

I now get a different error : missing ) after argument list

Different, but no less annoying. Any ideas ? Could there be a problem with passing a String with commas in it ?

Thanks for any insight !
0
 
COMPSUPPAuthor Commented:
Experts Exchange: Should I repost my question with a new title as I have a different error now ? I might get more responses to a new question..
Thanks
0
 
COMPSUPPAuthor Commented:
Ah...through trial and error I have found this works for FireFox. :

tinyPlusSubrowImage.setAttribute('onclick','test(\'' + ageSexPhaseString +'\')');
0
 
HonorGodSoftware EngineerCommented:
The important thing is getting it to work.

The next most important, at least in my opinion, is understanding it.

I'm glad that you got it resolved.

Thanks for sharing the answer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now