PDA

View Full Version : Javascripting problem


HTMLninja
05-27-2008, 01:37 PM
ok i am developing a website and i need to know if i can edit code with Javascript


so for i have tried to do it with a prompt box it didn't really work. i am trying to have the
visiter copy and paste the name of the game/url to get the game into the prompt box and have it load the game. i cant get it to work any ideas?

i want to have javascript edit the caps text to change the game based on user preference
embed
src="THIS IS WHERE I WANT TO EDIT THE CODE.swf"
width="600"
height="600"
allowscriptaccess="always"
allowfullscreen="true"

if this is not possible that is ok
but if there is another way to have a similar effect i would greatly apreciate it

cmetz1977
05-28-2008, 03:06 PM
I'm not sure I understand the problem, but i'll give it a shot.

you can add an id attribute to your embed tag (ie id='gameobject'). then:

gameurl = prompt( 'URL of Game?' );
if( gameurl ) document.getElementById( 'gameobject' ).src = gameurl + ".swf";

The way you seem to be doing this leaves a lot of room for user error. I would use SSI (PHP/ASP) to list available games as links (<a href='playgame.html?gameurl=path/to/game1'>Game 1</a>). When the playgame.html file is loaded, it would use the GET string ( 'gameurl=path/to/game1' ) to create a variable named 'gameurl' with the value of 'path/to/game1' and load the requested game.

<embed src='<? echo strtoupper( $gameurl ) ?>.swf' ....

This way shows all options, and only options. Using the prompt, you would have to develop a lot of error control for extra spaces, special characters, invalid formats, ...

HTMLninja
06-06-2008, 01:03 PM
Thank you very much