sazzie Posted January 17, 2007 Share Posted January 17, 2007 My course.php script has no html tags but it does declare and internal javascript function such as follows : [code] //include javascript to create calenders two instances needed for both coloured forms $javascript = "<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"CalendarPopup.js\" type=\"text/javascript\"></SCRIPT> <SCRIPT LANGUAGE=\"JavaScript\" type=\"text/javascript\"> var cal = new CalendarPopup(); </SCRIPT>";<form name="form1" action="" method="post"> <input name="testName" value=""/> <a href="#" onclick="cal.test(<?php print $g;?>);">Click for calendar</a></form>[/code]As you can see, the form attempts to call a function of CalendarPopup but IE and Firefox return a "Cal is Undefined" message. ???Please help. I know 100% that the Calendar Popup works beautifully so it is not the problem. Any suggestions? ;) Quote Link to comment Share on other sites More sharing options...
trochia Posted January 17, 2007 Share Posted January 17, 2007 Does this worl locally on your box, then not on a server? Quote Link to comment Share on other sites More sharing options...
sazzie Posted January 17, 2007 Author Share Posted January 17, 2007 No, the code simply compiles fine but the link fails to work properly. Instead of called the javascript function,the error message comes up. ::) Quote Link to comment Share on other sites More sharing options...
trq Posted January 17, 2007 Share Posted January 17, 2007 Here...[code]$javascript = "<SCRIPT LANGUAGE=\"JavaScript\"[/code]are you trying to save your javascript into a php variable? Quote Link to comment Share on other sites More sharing options...
sazzie Posted January 17, 2007 Author Share Posted January 17, 2007 No just to call the javascript when I use the onClick enabled link Quote Link to comment Share on other sites More sharing options...
trq Posted January 17, 2007 Share Posted January 17, 2007 Then all you need is....[code]<SCRIPT LANGUAGE="JavaScript" SRC="CalendarPopup.js" type="text/javascript"></SCRIPT><SCRIPT LANGUAGE="JavaScript" type="text/javascript"> var cal = new CalendarPopup();</SCRIPT>;[/code]This really has nothing to do with php. Quote Link to comment Share on other sites More sharing options...
sazzie Posted January 17, 2007 Author Share Posted January 17, 2007 I already tried this approach but the object is not being created.I don't understand why it doesn't recognise my javascript file so it can create the object. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted January 17, 2007 Share Posted January 17, 2007 Make sure you're supplying the correct URL to src in the link tag. Quote Link to comment Share on other sites More sharing options...
sazzie Posted January 18, 2007 Author Share Posted January 18, 2007 I think I found the problem.The $javascript object is not being created with the indicated text.[code] $javascript = "<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"CalendarPopup.js\" type=\"text/javascript\"></SCRIPT> <SCRIPT LANGUAGE=\"JavaScript\" type=\"text/javascript\"> var cal = new CalendarPopup(); var caltwo = new CalendarPopup(); </SCRIPT>";[/code]On echoing the contents of $javascript, I found there is nothing in there.Can anyone see what might be wrong!? :-\ Quote Link to comment Share on other sites More sharing options...
artacus Posted January 19, 2007 Share Posted January 19, 2007 Well a tip would be to use single quotes for your literal string so you don't have to escape all the double quotes.Actually I don't see any conditional processing here, so you should just include it outside of your php tags[code]<?php$g = 'whatever';?><html><head><script language='javascript'>var cal = new CalendarPopup();var caltwo = new CalendarPopup();</script></head><body>...[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.