Hi. I'm fairly new to PHP and i was writing a script in which i wanted to have some javascript included. I was wondering if someone could look this piece of the code over and tell me if this is even valid..
Umm, well not quite. I wouldn't use a NULL attribute at all, I'd use an isset() or !empty() function instead. I'd also adjust your <?php echo $var?> to simply adding a semi colon at the end of the variable. Don't think a one liner would cause problems, but I've never done it without so I'm not sure.
As for your javascript, I cannot help you validate that, I'm not much of a javascripter. What I can say, is depending on what you are doing there may be a different way to do the same thing using arrays in javascript. Simply due to $terrArray, if its like 20 for instance then you are going to have a lot of code which surely can be arranged in another way. Best to check with the js guys though for that one.
PHP has very little (if nothing) to do with JS. PHP just generates the code that is passed to the browser. If you print JS, JS will be sent and if that JS works it will be executed by the browser.
__________________
I'm not sure if this was any help, but I hope it didn't make you stupider.
Experience is something you get just after you really need it. PHP Installation Guide Feedback welcome.
yeah, JS cannot comunicate with php, but they can work together. PHP can dynamically generate the information that you need, but you cannot set a php variable with javascript. Now, there is I suppose one way to do it, you can use js to set cookies, and you can retrieve these with php. I've never done this before, as I mentioned, I'm not much of a javascripter, and don't know how everything works with it. The question is, do you really need javascript at all? I mean, I find more an more visitors to my sites do not support javascript with their browsers, and therefore I refuse to use it at all, at least for things that need to be done by php, but can shortcut with javascript (checking form fields for example). Otherwise, I find it pretty much useless.