Forum Moderators: coopster

Message Too Old, No Replies

PHP and Javascript

         

Triel

5:03 pm on Oct 15, 2008 (gmt 0)

10+ Year Member



Hi all, I am new here and pretty new to programming for the web (I was an RPG Programmer). But my question, not sure if it should be here or under javascript/ajax, is:

Is it possible to update a javascript menu from what is input into the form which uses php. See I have a photo gallery and the person posting into it needs to also go in by hand and enter the javascript for the new links on another site. The boss wants to automate this so that the person entering the promotions does not have to access these other files or know javascript. (These are 2 different sites even though they are for the same company. One is for internal and one is for external people.)

I figure it is probably possible if you put the links into MySQL but that would take a lot of programming to redo the whole site. He wants something that would not take a lot of time or big rewrite. Any ideas?

Thanks in advance!

cameraman

5:24 pm on Oct 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmaster World, Triel.

Sure, you can automate that with php and no mysql. In addition to generating content to send to people's browsers, you can use php to manipulate your own files. Use a function like file_get_contents [us3.php.net] (other Filesystem [us3.php.net] functions) to read the content of your javascript file, append the info, then file_put_contents [us3.php.net] to save the modified information. Depending on how the javascript is laid out, you may want to manually put in some markers to look for:
// Begin menu
var item1 = open_window('joseph');
var item2 = jump_menu('billy');
// End menu

Then you can look for "// End menu" so you know where to make the insertion.

Triel

5:51 pm on Oct 15, 2008 (gmt 0)

10+ Year Member



Thanks so much cameraman. I appreciate your input. After I look at this my son is telling me yes, that could be done like that if it were a javascript file. I look and the javascript is inline on a php page. So the page is index.php and the javascript is inside. He said I would have to rewrite the whole thing and make it a separate js file, which would take me too long to do. I am still a bit confused too as to why there is 2 places that need the menu links updated.

I think I need to look at this more closely. There is a js file which has all the menu items in it that also needs to be updated along with the inline javascript on the index.php file. I need to find out if there is a reason why the js file isn't just being used in both the main page and all the following pages. It does not make sense to me that the main page would not use the same js file instead of having it inline.

cameraman

6:22 pm on Oct 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That doesn't make sense to me, either - does the index.php file that has the javascript also have <javascript src="filename">?

It's still do-able, though, you'll just modify two places if that's how it's going to be; you can use php to modify a php file, it's all just letters and numbers...

The tricky part is figuring out the logic to pin down where the modification needs to be made, and definitely keep backups until the script is debugged (yes that's from direct experience)! That's why I suggest inserting markers.

Triel

6:48 pm on Oct 15, 2008 (gmt 0)

10+ Year Member



It does have a "script language="JavaScript" src="mm_menu.js"" but this isn't the menu itself, it is what sets the style of the menu up, such as height and width of the menu. This is after the inline javascript for the links. I don't see this source being called within the sub-pages. I still don't understand at this point why you would need to code it inline. But my son said he did it for a reason a long time ago and can't remember why. This mm_menu.js file is written by someone else, I think they purchased it.

But the boss does not want to put a lot of work (expense to the client) into getting this done.