Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 190
  • Last Modified:

button, script, disable

I have two scripts for a file upload form page. The first one it's a validation script to restrict the file types to be downloaded which is the following:

<script language="Javascript">

function validate(){
   str=document.form1.picture.value;
   strlen= str.length;
   strfiletype= str.substring(strlen-4);
 
 // alert(strfiletype.toUpperCase());
 
if ((strfiletype.toLowerCase() != ".doc") && (strfiletype.toLowerCase() != ".rtf") && (strfiletype.toLowerCase() != ".pdf") && (strfiletype.toLowerCase() != ".gif") && (strfiletype.toLowerCase() != ".bmp") && (strfiletype.toLowerCase() != ".jpg") && (strfiletype.toLowerCase() != "jpeg"))
 
   {
     alert("Sorry!! you can upload only word doc,rtf, jpeg, gif or pdf files");
     return false;
   } else
     return true;
}
</script>  

THE OTHER ONE IS FOR DISABLING THE BUTTON AND SHOW A "LOADING..." TEXT:

<SCRIPT language='javascript'>
function disableButton(theButton)
{
   theButton.value="Loading...";
   theButton.disabled = true;
   theButton.form.submit();
}
</script>

AND THE BUTTON CODE:

<input type="submit" onClick= "return validate();" name="attach" value="Submit File">

OBVIOUSLY WITHIN THE ONCLICK SOMETHING HAS TO BE DONE BUT WHAT?

THANKS FOR ANY SUGGESTION!
0
Nicola Siotto
Asked:
Nicola Siotto
  • 14
  • 11
1 Solution
 
basicinstinctCommented:
well you should change the function to this:

function disableButton(theButton)
{
   theButton.value="Loading...";
   theButton.disabled = true;
   //theButton.form.submit();
}

then call it like this:


<input type="submit" onClick= "disableButton(this); return validate();" name="attach" value="Submit File">
0
 
Nicola SiottoDirectorAuthor Commented:
It doesn't work. Or let me explain better... When I click the button, it gets disabled but the form doesn't load.
0
 
Nicola SiottoDirectorAuthor Commented:
Sorry I was making a mistake, now it works but another problem arises. It works also when for instance someone tries to upload an empty string or a wrong file type and this obviously invalidates the function of the other script. Any idea on how to fix this?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
basicinstinctCommented:
ok, i misunderstood what you wanted...

change the function back to this:

function disableButton(theButton)
{
   theButton.value="Loading...";
   theButton.disabled = true;
   theButton.form.submit();
}
0
 
Nicola SiottoDirectorAuthor Commented:
Still doesn't work, I mean when for instance you try to load an empty string or a wrong file type, the Alert displays right, but then it launches the form but the function of the other script is to stop the form if the right file is not loaded.
0
 
basicinstinctCommented:
ok, thought about it a bit more...

change the onclick to this:  

onClick= "return validate(this);"

and replace both functions with this:

function validate(theButton){
   str=document.form1.picture.value;
   strlen= str.length;
   strfiletype= str.substring(strlen-4);
 
 // alert(strfiletype.toUpperCase());
 
if ((strfiletype.toLowerCase() != ".doc") && (strfiletype.toLowerCase() != ".rtf") && (strfiletype.toLowerCase() != ".pdf") && (strfiletype.toLowerCase() != ".gif") && (strfiletype.toLowerCase() != ".bmp") && (strfiletype.toLowerCase() != ".jpg") && (strfiletype.toLowerCase() != "jpeg"))
 
   {
     alert("Sorry!! you can upload only word doc,rtf, jpeg, gif or pdf files");
     return false;
   }
   else
   {
     theButton.value="Loading...";
     theButton.disabled = true;
     return true;
   }
}
0
 
Nicola SiottoDirectorAuthor Commented:
Done, still when I click the submit button the button disables prior to loading, so it doesn't work!
0
 
basicinstinctCommented:
works fine for me in firefox and ie:

<html>
      <head>
            <script type="text/javascript">
            function validate(theButton)
            {
               str=document.form1.picture.value;
               strlen= str.length;
               strfiletype= str.substring(strlen-4);
             
               if ((strfiletype.toLowerCase() != ".doc") && (strfiletype.toLowerCase() != ".rtf") && (strfiletype.toLowerCase() != ".pdf") && (strfiletype.toLowerCase() != ".gif") && (strfiletype.toLowerCase() != ".bmp") && (strfiletype.toLowerCase() != ".jpg") && (strfiletype.toLowerCase() != "jpeg"))
               {
                 alert("Sorry!! you can upload only word doc,rtf, jpeg, gif or pdf files");
                 return false;
               }
               else
               {
                 theButton.value="Loading...";
                 theButton.disabled = true;
                 return true;
               }
            }
            </script>  
      </head>
<body>
      <form name="form1">
            <input type="text" name="picture"/>
            <input type="submit" onClick= "return validate(this);" name="attach" value="Submit File">
      </form>
</body>
</html>


Of course, the button wil only be disabled while the page is submitting - when the page reloads it will be enabled again... is this the problem you are encountering?
0
 
Nicola SiottoDirectorAuthor Commented:
I copied your entire page and as I told you the DISABLE function works fine ok but it stops the form loading therefore the form does not load the attachment for some reason.
0
 
Nicola SiottoDirectorAuthor Commented:
No the problem I am encountering is that when the button disables (as it should) the page stops and does not load or reload, it does nothing as a matter of fact.
0
 
basicinstinctCommented:
it should do nothing if the attchment is not the correct type right?  you don't want to submit the form unless the picture has the correct format...

i understand it like this:

--- If the picture ends with an acceptable extension disable button, change to "loading" and submit form

--- If the picture does not end with an acceptable extension display a message and do not submit form

Why would you want the form to submit if it doesn't validate?  it defeats the purpose of validation...

0
 
Nicola SiottoDirectorAuthor Commented:
You are correct. In fact I am telling you that everything runs fine (the validation). My problem is that when I browse and attach the correct file, I press the submit button and the button rightly disables, shows "Loading..." but then the page freezes instead of loading the content as requested. I hope to have clarified a bit more now. Thanks.
0
 
basicinstinctCommented:
yes, i see the problem now...

in short, i believe this question should be closed as we have solved the "button, script, disable" problems

to expand on this - the problems you are having now (page freezing) are due to problems in other parts of your code -  it will be a completely different part that is not really related to this at all.

you will need to provide information about what server side language you are using, and post the form tag (ie  <form action="........ )  depending what server side language you are using i may not be able to help you at all, it may require a new expert to come along, and a new question in the right area is the best way to get them to come along...

0
 
Nicola SiottoDirectorAuthor Commented:
Sorry but I slighyly disagree. Since the first minute I have written both scripts hence I was seeking to solve the issue. If the form stops working what would I need the code for? It is clear that the code requires some adjustment and this is why I have asked help in Experts Exchange. I hope that someone comes with a solution.
0
 
basicinstinctCommented:
what happens if you change this:

<input type="submit" onClick= "return validate(this);" name="attach" value="Submit File">

to this:

<input type="submit" name="attach" value="Submit File">

obviously the validation and button disabling code won't work, but if you provide the correct data does the form submit?
0
 
Nicola SiottoDirectorAuthor Commented:
It works but please note it was also working before me trying to implement the button disabling script. I think the solution might be to instruct the script maybe within the <form>. I am not sure how and whether it works but it's just an idea.
0
 
basicinstinctCommented:
is there a url to this site where i can take a look?
0
 
Nicola SiottoDirectorAuthor Commented:
Unfortunately the site is password protected and under construction. I will try to see now if I can at least duplicate the page and unprotect it for you to test it. Thanks!
0
 
Nicola SiottoDirectorAuthor Commented:
I have created a dummy page, unrestricted, that you can use to upload a dummy MS Word or PDF file so that you can test the page: http://006a4bd.netsolhost.com/portal/applicants/test.asp

The entire HTML of this page it's in the following TXT file: http://006a4bd.netsolhost.com/portal/applicants/test.asp

Please let me know if you need me to do something from my side. Thanks.
0
 
Nicola SiottoDirectorAuthor Commented:
0
 
basicinstinctCommented:
it works for me as it is...
can you put disable button script back in so i can see how it breaks...
0
 
Nicola SiottoDirectorAuthor Commented:
I have done as you requested:
http://006a4bd.netsolhost.com/portal/applicants/test.asp

You can download the entire HTML content at the following address: http://006a4bd.netsolhost.com/portal/applicants/test.txt

As you can see once you upload a file and click the "Submit File" button, it disables and changes into "Loading..." but it stops there and doesn't load the form and hence neither the files uploads, while as you might have toticed before it should give a success response page.

Awaiting further instructions... thanks!
0
 
basicinstinctCommented:
works like a charm in Firefox...
i tried it in IE6 and yes, not too surprised to see that it doesn't work... IE is a very cr@ppy browser... i'm pretty sure that's what you're using...

this should make it work in all browsers, even the cr@pest of the cr@p...

add this line back in: theButton.form.submit(); so it looks like this:

     theButton.value="Loading...";
     theButton.disabled = true;
     theButton.form.submit();
     return true;


But in the HTML change this:

<input type="submit" onClick= "return validate(this);" name="attach" value="Submit File">

to this:

<input type="button" onClick= "return validate(this);" name="attach" value="Submit File">
0
 
Nicola SiottoDirectorAuthor Commented:
It works and I really appreciated your dedication to this problem.
I totally agree with you, IE it's second to other browsers but it's the most used browser and therefore if it doesn't work there most people won't be able to use our site.

Anyhow I wish I could give more points as your dedication was outstanding, really!

Thanks and regards.
0
 
basicinstinctCommented:
my pleasure, glad we got it in the end.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 14
  • 11
Tackle projects and never again get stuck behind a technical roadblock.
Join Now