Jump to content

Recommended Posts

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.

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.