Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looking online for 7hrs for Disable for Field

Status
Not open for further replies.

chlebicki

Technical User
Jul 4, 2006
31
US
Hi,

I have been searching all over the net on how to disable a form field via a javascript command. It seems pretty straight forward but for some reason I can't get it.

Here is what I have done based on my research so far:

Above the webpage's body.....

<cfoutput query="rsPamInformation">
<script language="javascript">
function enableField()
{
document.form1.upload_#rsPamInformation.PAM_ID#.disabled=false;
}
</script>
</cfoutput>


Checkbox in webpage's form...
<input name="checkbox" type="checkbox" value="checkbox" onclick="enableField()"/>


Here is the File Form do be disabled...
<input type="file" name="upload_#rsPamInformation.PAM_ID#" disabled="true"/>


The file form to be disabled is disabled when the webpage is loaded, but when I click on the checkbox nothing happens. So the disable="true" is working...meaning it's disabled, but I can't renable the file form via the checkbox...anyone see anything wrong?

Thanks again for all your help,
~Craig
 
it very well could be that you are not referencing the field properly with document.form1.upload_#rsPamInformation.PAM_ID#.

this implies the form name is form1, is it?

can you give the file field an ID and use document.getElementById ?

also, have you viewed source on this page, i notice you build the function inside of <cfoutput query="rsPamInformation">, what if that query returned more than 1 row? you'd get multiple functions written to the page with the same name.

if the file field is not in a cfoutput query="" , but rather a simple cfoutput, then that variable would reference the first row of the query, but if you had multiple functions defined with the same name, i 'think' it would just pick up on the last one (last row of the query). - so the reference to that field would be invalid.

none of this could be valid but it's all i can tell looking at the code, there is nothing wrong with the way you are setting the disabled property in javascript - which makes me think it is something else altogether.

=========================================
Don't sweat the petty things and don't pet the sweaty things.
 
NorthStarDA,

I took some time and tried what you suggested. I took out the cfoutput query and hardcoded the ID. I then checked the page sources to confirm the filefield's name in the brower was matching up with my hardcoded filefield name. So this is what I had....


Above the webpage's body.....
<script language="javascript">
function enableField()
{
document.form1.upload_5.disabled=false;
}
</script>

Checkbox in webpage's form...
<input name="checkbox" type="checkbox" value="checkbox" onclick="enableField()"/>


Here is the File Form do be disabled...
<input type="file" name="upload_#rsPamInformation.PAM_ID#" disabled="true"/> (which in the pagesource displays upload_5)


I played with the true/false settings in the javascript and that didn't do anything. Again, the file form is disabled, but the checkbox doesn't do anything, so I think you are right it is not referencing the function correctly I just don't see what's wrong. (the form is named form1)

Thanks,
~Craig
 
can you run this page and view source + copy the outputted source here? then we can easily tell the problem.

=========================================
Don't sweat the petty things and don't pet the sweaty things.
 
NorthStarDa,

After trying every way possible and still not getting any success, I got it working via a work-a-round. I instead used FlevOOware's behavior that let's you enable/disable objects. I would have used this before, but the problem was FlevOOware's behavior didn't let you chose to disable/enable a form field if that field's name is a variable (I guess because the name doesn't exist yet.)

So I still inserted the behavior by choosing an existing field, and then manually changed the FlevOOware's Code to the field I wanted to disable (who's name is a variable). Probably not the 'best' way, but it works.

Thanks,
Craig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top