Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Nov 2005
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Disable/Enable Submit Button

    HI

    Can anyone tell me what would be a quick and easy way to to enable and disable a submit button, on selecting a yes or no question(radiobutton or selectbox)???

    Thanks

    V

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Code:
    <form>
    <input name="rad" type="radio" value="Yes" onclick="this.form['sub'].disabled=false"> YES
    <br>
    <input name="rad" type="radio" value="No" onclick="this.form['sub'].disabled=true"> NO
    <br>
    <br>
    <input type="submit" name="sub" value="Submit" disabled>
    </form>
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New Coder
    Join Date
    Nov 2005
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks Kor

    V
    (Go Romania!)

  • #4
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Imho, it's a better idea to use js to initially disable the button.
    By hard-coding the disabled attribute, those without js won't have the ability to enable it again, leaving them with a button they can't use and a form they can't easily submit.

    e.g.
    Code:
    window.onload = init;
    
    function init() {
    
    	if (!document.getElementById) return;
    
    	var submitObj = document.getElementById('sub');
    	submitObj.disabled = true;
    
    }
    Code:
    <input type="submit" name="sub" id="sub" value="Submit">
    Last edited by Bill Posters; 09-06-2006 at 01:49 PM.

  • #5
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Yes and no. I thought about that. Some will might disable js just to be able to submit withouth checking the radio, so that, later they might invoke that they were not agree the disclaimer (or whichever might mean those radios), or things like that. Unless you have a server-side validation application as well (which you must have) keep the disabled on a default HTML level.

    The story with javascript disabled starts to ennoy me somehow. I work with a lot of applications (admins like plesk) wich need javascript, so that I know where I can enable or where I must disable javascript (althought I usually don't disable it, unless I am to enter in an highly untrusty site - I prefere to disable rather cookie and popups accept than the whole javascript). So that I don't understand people which disable javascript. If you disable an important web feature, you must know that most of the time you will not be able to follow everything on a web page. This is it. The following step after disable javascript might be disable CGI or even HTML code... Now what?

    The simple fact that one can disable something does not mean that he must do that all the time. If one is interested in a site, than he must follow the minimum rules of that site. To enter a site (unless is an educational or gouvernmental one) is not compulsory, as it is not compulsory to buy a book or to enter a shop and buy something. Who wants, should enter through the entrance door, not through the back window.
    Last edited by Kor; 09-06-2006 at 03:50 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #6
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by Kor View Post
    Yes and no. I thought about that. Some will might disable js just to be able to submit withouth checking the radio, so that, later they might invoke that they were not agree the disclaimer (or whichever might mean those radios), or things like that. Unless you have a server-side validation application as well (which you must have) keep the disabled on a default HTML level.
    And what of those who are using UAs which don't support js?
    Accessibility isn't a big feature of your approach.

    Using a checkbox saying 'I agree' is only any good if you base agreement/consent on whether or not the checkbox is checked.

    The use of the checkbox to denote consent is largely an arbitrary convention made to make the act of giving consent more straight-forward. It's no more legally binding than an agreement/act of consent statement which makes the submitting of the form itself the act of agreement/consent.

    Heck, keep the checkbox as the act of consent, leave the submit button alone (i.e. don't disable it) and, as you suggest, use server-side validation.
    Then, if you want, throw in some post-load js to disable the submit button by default as an additional means of relating the requirement of consent and consent pre-validation.

    Disabling the submit button in the markup really is a bad idea.

    The story with javascript disabled…
    …is missing the point. Not all non-js UAs are simply js-enabled GUI browsers with js switched off.

    I think you should read up on what rights legislation such as the Disability Descrimination Act (UK) and other similar acts around the world do give to users who may be using non-js UAs through necessity rather than choice.

    The very fact that you deny access to those without js could well be considered an act of descrimination which could result in a lawsuit being made against a site which employs such techniques.


    You say that you thought about it, but without wishing to cause offense, I don't think that you thought about it for long enough. The accessibility issue of how UAs which don't support js in the first place might access/use the page doesn't seem to have occured to you.
    This doesn't just mean assistive technology. It also means some mobile internet devices.
    By making the site inaccessible to those without js, not only are you potentially opening the site owner up to a lawsuit on the grounds of descrimination, but you're also locking out users of non-js AT or mobile devices, many of whom may have become valuable visitors, users, readers or even paying customers.
    Last edited by Bill Posters; 09-06-2006 at 04:18 PM.

  • #7
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    I've read those acts. They refere to the official, educational, general purpose sites. No one can tell me how to do my site.

    On the other hand there are now displyas which may read javascript codes even for blind people. And mobile devices who can do that. The simply fact that, for a moment, in related braches technology has not yet achieve the desired precision ( for different reasons or different interests) must not deny me to build my site as I wish.

    Speaking about discrimination... Hm, as a web designer I feel also discriminated by those who claime discrimination acts. You know, discrimination has two edges...
    Last edited by Kor; 09-06-2006 at 05:17 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #8
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by Kor View Post
    I've read those acts. They refere to the official, educational, general purpose sites. No one can tell me how to do my site.
    Possibly not, but that depends on whether you offer a service or not.

    Of course, what you can or cannot do on your site is also irrelevant to this thread as you weren't recommending ways for the OP to design your site.
    In the absence of a proper understanding of the type of site the OP was putting together (for which the recommended technique was destined), it's far better to err on the side of caution and give advice that gives equal access with or without js, thereby making the issue of whether the dependence on js would mean that the site is contravening anti-descrimination legislation completely academic.

    Speaking about discrimination... Hm, as a web designer I feel also discriminated by those who claime discrimination acts. You know, discrimination has two edges...
    I totally agree.
    I've long been a quite vocal opponent of disability descrimination legislation* on the grounds of that by enforcing the 'freedoms' of certain groups to browse privately-owned websites, we take away freedoms from those providing the site/service.
    (* by which I mean that I've ranted about it on web forums more than a few times. )

    However, very few people seem to care about that side of things.
    In the past, I've been called a callous, ignorant bast**d (or words to that effect) for even voicing the view that enforcing the rights of certain users to access and shop on a privately-owned company website is a gross abuse of the law.
    Holding such a view is considered by some to be up there in terms of evil on a par with kicking puppies and eating live babies.


  • #9
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    eerr... again yes and no... a rule is somehow better than no rule. But the rule which says that no other rules are valid is the first step to a dictatorship. If we all would be obliged to work for the lower, not for the performance, all of us will die. Believe me, I know what i say, I lived for 30 years in a communist country, and I know how dictatorship starts, ends and dies.

    It starts like that: don't use javascript, don't smoke, don't ... don't...don't...don't.... Do it for the "lowercase" person, chop off the elite, we don't need bright solutions for bright people. We need poor solutions for poor people.

    Well, it ends simply like that: f**k your stupid rules (pardon my *, but really I have not found another real "accepted" word to say that &#%$@%$% ) .... - another stupid interdiction...

    The present? He, don't worry, it is the the same on our Europe Est European contries. You may say whichever, but who is listening you?

    I know what I say. You, the westerners, should hear what we are talking about. We know how the evil/devil is like, you do not.... ...Not yet...
    Last edited by Kor; 09-06-2006 at 10:48 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #10
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by Kor View Post
    It starts like that: don't use javascript, don't smoke, don't ... don't...don't...don't.... Do it for the "lowercase" person, chop off the elite, we don't need bright solutions for bright people. We need poor solutions for poor people.
    To bring this back on-topic…

    Again, I thnk you're missing the point, specifically the point of 'progressive enhancement / graceful degradation'.
    By having the disabled attribute hard-coded, only those with js will be able to submit the form.
    If having js enabled is a formal criteria for entering and accessing the site or making use of the content on the site (i.e. a js script repository), then there might be a good defense for making entry dependent upon having js available.
    If the content on the other side doesn't rely on js, which most sites typically don't, why make access to it reliant on js?

    Like I say, the technique I recommend gives access to both, but implements that additional, client-side check for js-enabled users which you seem to feel makes so much difference.

    You aren't excluding the js 'elite', your simply providing a scalable procedure that offers a bare-bones procedure for those without js and a more dynamic procedure for those with js.

    No-one is being forgotten - and that's the point of 'progressive enhancement' and 'graceful degradation'.


    Well, it ends simply like that…
    Try to separate out your own feelings on broader issues from your ability to provide sensible, useful advice. It currently seems that your own anger and bitterness over certain social and political issues is encroaching on the quality of your advice, which can potentially damage the chances of success of those who take your advice.

    Tbh, I've no real interest in discussing either yours or my own views about the evils of prioritising 'lowercase people' in depth - at least, not here, not now and not in this thread.
    I suggest you try to resolve your political issues/rant somewhere other than a web design forum - or at the very least, save discussion of them for a dedicated thread.

  • #11
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    ok ok... I give up regarding this topic. Probably is better to disable the submit button on using javascript onload.

    But I do not give up regarding the general javascript disabled/enabled issue. And you were the one who provoked, what you said, in not a very polite manner, as to be "my bitterness over certain social and political issues". Yet this is another topic, we could probably open another separate thread on this issue and let this thread to be closed, as I guess nothing more usefull can be added here at the moment.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #12
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is what I did for my submit button.

    Code:
    <script type="text/javascript">
          function flip(obj,submitbutton)
                {
                   submitbutton.disabled=true; submitbutton.style.color="#000000";
                   if (obj.checked){submitbutton.disabled=fasle; submitbutton.style.color="#ffffff";}
                }
    </script>
    Code:
    <input type="checkbox" onclick="flip(this,this.form['sub']);">I Accept</input>
    Code:
    <input type="submit" name="sub" value="Login" disabled></input>
    This way if you uncheck the checkbox the button goes back to disabled.
    Just another solution. Works great for me.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •