0

I'm pretty new to web programming (and I'm a self-taught) so I'm often confused by multiple ways of doing something.

My goal is to set the "disabled" attribute to all input hidden. Further on I'll try to remove it while showing the inputs and re-add it while hiding them. Reading around I've been able to write the below code but it works on a test page and it doesn't in my real context. (Furthermore it seems to give problems to the browser sometimes).

My questions are:
is the code correct?
is there another (simpler/better) way to do this?

var HidInp = document.querySelectorAll(".HideIt");
for (i = 0; i < HidInp.length; i++) {
    var Inputs = HidInp[i].getElementsByTagName('input');
        for (ii = 0; ii < Inputs.length; ii++) {
            Inputs[ii].setAttribute("disabled", "");
        }
}

P.S. I've also tried using the function in this answer

genespos
  • 3,211
  • 6
  • 38
  • 70
  • Please share the relevant markup as well. Preferably, try to create a working snippet. – gurvinder372 Jan 17 '18 at 12:17
  • What differs between your test page and your real context? What errors appear in your browser's console? – Andy G Jan 17 '18 at 12:18
  • ".HideIt" class added on which input you want to "disabled"? – Hanif Jan 17 '18 at 12:30
  • _@ gurvinder372_@AndyG_@Hanif sorry, I'm not able to identify (and so to give) "the relevant markup". I get no errors in the console. Anyway I succeeded in solving by modifying my php (so I don't need any more javascript). Thanks for your time and attention. – genespos Jan 17 '18 at 15:53

0 Answers0