Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

javascript missing : after property id

Posted on 2009-05-11
11
Medium Priority
?
1,140 Views
Last Modified: 2012-05-06
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
Comment
Question by:COMPSUPP
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 41

Expert Comment

by:HonorGod
ID: 24354372
in the THEN clause, you probably want to use something like:
tinyPlusSubrowImage['onclick'] = new function( test( ageSexPhaseString ) }

Open in new window

0
 

Author Comment

by:COMPSUPP
ID: 24354476
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
 
LVL 41

Expert Comment

by:HonorGod
ID: 24355053
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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

Author Comment

by:COMPSUPP
ID: 24355265
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
 
LVL 41

Expert Comment

by:HonorGod
ID: 24355393
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
 

Author Comment

by:COMPSUPP
ID: 24355481
Yes, I thought object detect code was what I was using with:

if ((document.all) && (document.getElementById))
    {
    }else{
}
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 24356056
Yes, I just tend to jump on the phrase "browser detect". :-)  Sorry about that.
0
 

Author Comment

by:COMPSUPP
ID: 24356255
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
 

Author Comment

by:COMPSUPP
ID: 24356277
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
 

Accepted Solution

by:
COMPSUPP earned 0 total points
ID: 24356419
Ah...through trial and error I have found this works for FireFox. :

tinyPlusSubrowImage.setAttribute('onclick','test(\'' + ageSexPhaseString +'\')');
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 24356729
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

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question