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 9 of 9
  1. #1
    Regular Coder
    Join Date
    Apr 2010
    Posts
    417
    Thanks
    4
    Thanked 1 Time in 1 Post

    how to enable dynamic form fields if JS turned off.

    I have a form that only shows the submit (update) buttons if the value select field beside it is changed. But what is someone has JS disabled, how can I enable them?

    Code:
    <select title="3553" name="3553" onchange="JavaScript:document.cart.add3553.disabled=false;">

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,585
    Thanks
    23
    Thanked 645 Times in 644 Posts
    You can not enable a users javascript. You have to ask them to do it.

    You can put up a message that js is needed to use your site or
    On the page that needs js make an alert that asks them to turn js on and do a onload that will remove it if they do have it on.

    Those are the methods i use. Any other ideas?

  • #3
    Regular Coder
    Join Date
    Apr 2010
    Posts
    417
    Thanks
    4
    Thanked 1 Time in 1 Post
    Having re-read me own post, I realised I was asking the question the wrong way around.

    What I should be asking is how do I set only the 'update' submit buttons, only the buttons within a certain form called 'cart', to 'disabled'

    My page can have two forms and on certain pages up to three forms, each form of course has a different name. So I do not want to disable every submit button on the page, only those within the form called 'cart'

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,243
    Thanks
    203
    Thanked 2,555 Times in 2,533 Posts
    If Javascript is not enabled in the user's browser, then you cannot use Javascript to disable or enable some or all submit buttons. You need to advise your users that they must have Javascript enabled to use the site.

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    Regular Coder
    Join Date
    Apr 2010
    Posts
    417
    Thanks
    4
    Thanked 1 Time in 1 Post
    ok what i was after is to allow all buttons to be enabled and only if they have JS enabled woyuld I be able to disable them to prevent the buttons being clicked for the hell of it when nothing was changed on the page.

    I have been rooting around again and got this code before which changed all the input fields to autocomplete off, but when I change the code to check for submit buttons it fails.

    here is what I have...
    the if statement fails with...

    Error: theTags[i].name is undefined

    Code:
    function disableUpdateSubmit() {
    var theTags = document.getElementsByTagName('*');
    	for(i=0;i < theTags.length;i++) {
    	   if(theTags[i].name.substring(0, 2) = 'add') {
    	   theTags[i].disabled=true;
    	   }
    	}
    }

  • #6
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    I assume not all of your tags on the page have a name attribute? So you can not extract a substring from it ... that's what the error is about
    Code:
    function disableUpdateSubmit() {
    var theTags = document.getElementsByTagName('*');
    	for(i=0;i < theTags.length;i++) {
    	   if(theTags[i].name) {
                  if(theTags[i].name.substring(0, 2) = 'add') {
    	         theTags[i].disabled=true;
    	      }
               }
    	}
    }

  • #7
    Regular Coder
    Join Date
    Apr 2010
    Posts
    417
    Thanks
    4
    Thanked 1 Time in 1 Post
    oh I see, I now have this errror showing..

    Error: invalid assignment left-hand side

    on this line

    Code:
    if(theTags[i].name.substring(0, 2) = 'add') {

  • #8
    Regular Coder
    Join Date
    Apr 2010
    Posts
    417
    Thanks
    4
    Thanked 1 Time in 1 Post
    the submit buttons that i wish to disable all start with

    'add'

    i.e.

    add124
    add7647
    add24565
    add2
    add6337

  • #9
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    Sorry, my bad

    I oversaw the second more obvious mistake. The compare operator is == and not =
    Code:
    function disableUpdateSubmit() {
    var theTags = document.getElementsByTagName('*');
    	for(i=0;i < theTags.length;i++) {
    	   if(theTags[i].name) {
                  if(theTags[i].name.substring(0, 2) == 'add') {
    	         theTags[i].disabled=true;
    	      }
               }
    	}
    }


  •  

    Posting Permissions

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