-1

I have a contact form on my website that emails me info from interested parties. I don't want to use a captcha for various reasons. I just want to do something simple, like disable the submit button on the form until the user answers a simple question. Hopefully this will keep out some bots at least. I found this on the web but it does absolutely nothing:

<script>
document.getElementById("Submit").disabled=true;
</script>

Can someone either correct this or give me something better?

Justin Ethier
  • 122,367
  • 49
  • 219
  • 273
user1675122
  • 1
  • 2
  • 5
  • 2
    Please at least provide your html – James Montagne Feb 06 '13 at 22:03
  • Try: `document.getElementById("Submit").setAttribute("disabled","true");`. It's about the same thing but it is worth the try! Also make sure that the ID is actually `Submit` and not `submit` – Shawn31313 Feb 06 '13 at 22:04
  • JavaScript will never help against bots. They will keep sending requests to your server. – Bergi Feb 06 '13 at 22:08
  • @Shawn31313: No. Setting the property is fine and should be prefered. – Bergi Feb 06 '13 at 22:08
  • Yes, I agree it's prefered. It was just a suggestion. – Shawn31313 Feb 06 '13 at 22:10
  • @OP: Do you have a button with the id `Submit`? When do you execute that line? Placing it inside ` – Bergi Feb 06 '13 at 22:11

1 Answers1

0

First of all make sure that if you are just testing that code that you have it in an onload function as such:

window.onload = function(){
    document.getElementById("Submit").disabled=true;
}

Also make sure that the ID is actually Submit and not submit because JavaScript is case-sensitive.

JSFiddle: Example of disabling a button.

Shawn31313
  • 5,772
  • 3
  • 29
  • 75
  • Ok I didn't use it as a function just put it inline after the form tag. I haven't written the test question code yet I wanted to see if the form button would get disabled. Someone asked about the html form code. here it is I apologise for the formatting I tried indenting to creat a code block but it doesn't work on your forum. – user1675122 Feb 06 '13 at 22:51
  • Did my solution fix it though? – Shawn31313 Feb 08 '13 at 00:38
  • No :( it doesn't on my computer. I don't really know how to use JSFIDDLE though. I did click run at the top and the "Doesn't Work" button got the focus. – user1675122 Feb 08 '13 at 04:41
  • Everybody I have had contact with on this forum has been real nice. I hate the structure of the forum itself though. No other forum I know of limits your input the way it does. Maybe I'll find y'all on again on a less constrictive forum! :) – user1675122 Feb 08 '13 at 06:39
  • @user1675122 This is a nice forum. You just have to get used to it. This is the number one forum for programmers I believe. Plus, you don't need to click on the run on JSFiddle. If you look in the `results` area. The first button is disabled because of the `JavaScript`. – Shawn31313 Feb 10 '13 at 16:56
  • Ok thanks! I don't have much room here for a comment, but I am using now a form and captcha hosted by a remote website. It functions well but would have been better if I could have programmed my own :( – user1675122 Feb 10 '13 at 23:04