Imad Posted September 4, 2008 Share Posted September 4, 2008 Hi guys, I need help with this. I've created the code below to echo "Searching Database" when the submit button is pressed: <script type="text/javascript"> function load() { document.spin.write('<img src="images/wheel.gif" />Search Database...'); }</script> spin would be the div as shown below: <div id="spin"></div> and here's the submit button of what tries to trigger it. <input type="image" src="images/search_button.png" class="submit" name="submit" id="submit" onclick="load()" /> I want it to be able to echo the text in the javascript function between the div of spin but it doesn't seem to work. Any help would be appreciated. Best Regards. Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted September 4, 2008 Share Posted September 4, 2008 Try something like: <script type="text/javascript"> window.onload = function() { var submit = document.getElementById('submit'); var spin = document.getElementById('spin'); submit.onclick = function() { spin.innerHTML = '<img src="images/wheel.gif" />Search Database...'; } } </script> . . . <div id="spin"></div> . . . <input type="image" src="images/search_button.png" class="submit" id="submit" /> You may need to rename the submit variable within the script...I'm not sure if that's a JavaScript keyword or not. Quote Link to comment Share on other sites More sharing options...
Imad Posted September 4, 2008 Author Share Posted September 4, 2008 Thanks that worked! is their any possible way to make it show for 5 seconds then continue with the form submission? Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted September 4, 2008 Share Posted September 4, 2008 Thanks that worked! is their any possible way to make it show for 5 seconds then continue with the form submission? You can do it with setTimeout. Something along the lines of: <script type="text/javascript"> window.onload = function() { var submit = document.getElementById('submit'); var spin = document.getElementById('spin'); submit.onclick = function() { var myTimeout = setTimeout("spin.innerHTML = '<img src=\"images/wheel.gif\" />Search Database...'", 5000); //continue submission } } </script> More info on the function here: http://www.w3schools.com/js/js_timing.asp I escaped the inner double-quotes in the first argument just to be safe. To be honest, I'm also not sure if an assignment will work there, but it can't hurt to try. 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.