Jump to content

Very Simple Question! Help!!!


TheFilmGod

Recommended Posts

I'm new to javascript. I have never used it before. This is a special ocassion! 8) 8) 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?

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.