Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onclick function not woring

Status
Not open for further replies.

gunio6

Programmer
Joined
Jun 13, 2006
Messages
7
Location
AT
Hi ,


i am implementing a javascript calendar in a web2 application.
i am using dynarch calendar ( )
the calendar works fine. there is one init function in my base HTML document that initializes the calendar.

<script type="text/javascript">
Calendar.setup({ inputField : "textID", ifFormat:"%Y-%m-%d %I:%M %p", showsTime:true, button:"date_1", step:1});
</script>

the calendar works fine , but only when the textID is set in the html text field properties. the problem is that this text id is php variable and that it is set dinamically.

i was wondering can i attach the above initialisation function to an image with onclick event?

i tried

onclick="Calendar.setup({ inputField:"<?=$elm_id?>", ifFormat:"%Y-%m-%d %I:%M %p", showsTime:true, button:"date_1", step:1});

but it shows syntax error!

any suggestions?

thanx
 
That's more a php question, isn't it?

Cheers,
Dian
 
well if you concider the onclick event to be a php issue then i will concider changing the forum :)

ps. i dont think this is a php question! the only php think is one variable!
 
Maybe I don't understand the question.

If it works setting the variable in the html and not from the php, it's a php error since javascript only knows about the html the page shows.

Cheers,
Dian
 
well you misunderstood me then. I am trying to initialize the calendar with onclick Javascript event which gives me syntax error. I am trying to do that because it sounds more convenient instead of generating javascript with php. I have onclick function with bunch of params in it

onclick="Calendar.setup({ inputField:"<?=$elm_id?>", ifFormat:"%Y-%m-%d %I:%M %p", showsTime:true, button:"date_1", step:1});

it initializes an object where one of the parameters is php variable. It should work but it doesn’t and it has nothing to do with the php variable. It’s more because I am not that familiar with JS syntax. And I do think that the question is for this forum!
 
There is no syntax error that I can see with that line. Perhaps the syntax error is elsewhere - OR... the PHP is outputting something that has odd characters in it (like braces, quotes, etc).

Can you show the CLIENT-SIDE output that your page has (i.e. after the PHP has been parsed)?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Oh, I see.

Then you miss a quote just before the semicolon.

Cheers,
Dian
 
Ok , i see that the php got you guys confused : )
the above code doesnt work even if i take the variable out and change it with static one.

onclick="Calendar.setup({ inputField:"date1", ifFormat:"%Y-%m-%d %I:%M %p", showsTime:true, button:"date_1", step:1});


the debuger says "syntax error: ( expected"

can it be that onclick doesnt support object initialisation but only function call. maybe the {} and the : confuse the interpreter?!?
 
the quote is there. sorry i didnt copy the whole thing.
 
You need to change out your quotes.
In your posted code you do not have an end quote on the line though that may be a cut/paste error.
But you are using double quotes for everything which is going to cause you problems. Change the outer quotes to singles. Normally I change the inner quotes to singles but I am not familiar enough with PHP to know if it makes a difference there (it does in ASP).
Code:
onclick=[COLOR=red]'[/color]Calendar.setup({ inputField:"<?=$elm_id?>", ifFormat:"%Y-%m-%d %I:%M %p", showsTime:true, button:"date_1", step:1});[COLOR=red]'[/color]

Google, you're my hero!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top