TheFilmGod Posted July 29, 2007 Share Posted July 29, 2007 I'm new to javascript. I have never used it before. This is a special ocassion! 8) <script type="text/javascript"> document.write_story.picaltinput.disabled; document.write_story.picuploadinput.disabled; </script> This is at the head of my document. I want javascript to go to those input fields and add disabled="true". At this time, the disabled feature has not been put in the code. So no "disabled" or "disabled=false" exist! I want this to work like this: When you have javascript turned off, the inputs are not disabled. But when it is on, I want them disabled unless they click on the radio buttons. The buttons work just fine. I just can't get the first step to work. Summary: NO JAVASCRIPT = not disabled input field Javascript on = disables input field This is all I want it to do. What I am doing wrong? Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted July 29, 2007 Share Posted July 29, 2007 here you go <form id="myform"> <fieldset> enable input:<input type="radio" onclick="changeInputStatus(this.value)" name="inputStatus" value="false" /> disable input:<input type="radio" onclick="changeInputStatus(this.value)" name="inputStatus" value="true" /> </fieldset> <input type="text" name="text1" /> </form> <script> //this variable refers to the input box now var element=document.getElementById('myform').text1; function changeInputStatus(setDisabled){ setDisabled=eval(setDisabled); if(setDisabled==true){ element.disabled="disabled"; } else{ element.disabled=""; } } //disables the input changeInputStatus(true); </script> Quote Link to comment Share on other sites More sharing options...
mainewoods Posted July 30, 2007 Share Posted July 30, 2007 set disabled to true or false: element.disabled=true; element.disabled=false; Quote Link to comment Share on other sites More sharing options...
nogray Posted July 30, 2007 Share Posted July 30, 2007 You're running your javascript code before the input field are rendered by the browser. Make sure your code runs after the page is loaded (body onload event) place the code after the input field (like DJ Kat example). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.