Voldemort Posted June 7, 2007 Share Posted June 7, 2007 I'm trying to make a section on my site where a user enters their name into a form, presses submit, and an image (theirname.gif) is shown, without reloading the screen. This is what I have right now, but it's not working... <html> <head> <title>New Page 1</title> </head> <body> <script language=javascript> function showimage (elem) { var url = elem.username.value; var imagearea = document.myimage; imagearea.innerHTML = "<img src='images/" + url + ".gif' />"; } </script> <form name="form" method="POST" action="javascript:showimage(document.form)"> <p align="center">Enter your name:<br> <input type="text" name="username" size="20"><br> <input type="button" value="Submit" name="enter" onclick="javascript:showimage(document.form)"></p> </form> <div name="myimage"> </div> </body> </html> images/(name).gif is a php image by the way Quote Link to comment Share on other sites More sharing options...
nogray Posted June 7, 2007 Share Posted June 7, 2007 use id instead on name for the div <div id="myimage"></div> and replace this var imagearea = document.myimage; with var imagearea = document.getElementById('myimage'); Quote Link to comment Share on other sites More sharing options...
Voldemort Posted June 7, 2007 Author Share Posted June 7, 2007 I also need to make sure nothing bad can be input... would just encodeURI() work fine? Quote Link to comment Share on other sites More sharing options...
nogray Posted June 7, 2007 Share Posted June 7, 2007 It's better to clean the value in the backend (PHP for example) this way if someone type in your URL with the bad text directly it deosn't cause any problems. Quote Link to comment Share on other sites More sharing options...
Voldemort Posted June 7, 2007 Author Share Posted June 7, 2007 It's already clean on the PHP side, but the page itself will show the text of what was entered and the picture, i.e. Smile 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.