Cannot execute javascription function in cfdiv

I am trying to disable a form field via javascript inside of a cfform that is inside of a cfdiv.  The javascript function is also inside of the cfdiv but outside of the cfform.

When I try to execute the function, it keeps on coming back and saying that the function is not defined in Firebug.

I am trying to do something like the following but it won't run.

<script type="text/javascript">
function disable_enable(){
if (document.all || document.getElementById){
if (document.test1.test2.disabled==true)
document.test1.test2.disabled=false
else
document.test1.test2.disabled=true
}
}
</script>

Does anybody know how I can get a javascript function?

Thanks in advance.
SFTProdAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gurpreet Singh RandhawaCEOCommented:
Can we see in a working URL, Please provide
SFTProdAuthor Commented:
There is no working URL.  The development is on my workstation.
Gurpreet Singh RandhawaCEOCommented:
your this code!

if (document.test1.test2.disabled==true)
document.test1.test2.disabled=false
else
document.test1.test2.disabled=true

has

test1 as form name
test2 is the input field value

try this way!

document.getElementById('test2').disabled
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

SFTProdAuthor Commented:
The problem is not so much the code.  I can replace everything in the code with

<script language="javascript">
Function Test() {

}
</javascript>

<cfform>
  <cfinput type="radio" name="radiobutton" onchange="Test()>
</cfform>

When I click on the radio button, it tries to call "Test()" but it throws an exception in Firebug saying that the function does not exist but it clearly does.

When I take the same function and put it on an HTML page without being in the CFDIV, it works fine.
gdemariaCommented:

The javascript has to be in the main page, you cannot put the javascript functions in the CFDIV opened by ajax.   You can call the function in the cfdiv, but the function must already exist on the main page.

You just need to move your js function to your header or cf template that contains your cfdiv.  That should fix it

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Brijesh ChauhanStaff IT EngineerCommented:
Use AJAXONLOAD, that is the only way to call JS function inside CFDIV / CFWINDOW, here is an example to help you out

You have to place your JS function on the main page.

<script type="text/javascript">
   fnSetFocus=function() {
      document.getElementById("SetFocus").focus();
      document.getElementById("SetFocus").select();}
</script> 

Open in new window


<cfform action="#CGI.SCRIPT_NAME#" method="get" name="FormEmployee">
   <input name="NameFirst" type="text" id="SetFocus" value="" />
   <input name="NameLast" type="text" value="" />
   <input name="Submit" type="submit" value="SUBMIT" />
</cfform>

<cfset AjaxOnLoad("fnSetFocus")> 

Open in new window

Brijesh ChauhanStaff IT EngineerCommented:
gdemariaCommented:

> that is the only way to call JS function inside CFDIV...

Not True.   Your solution will likely work, but is not the only way
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.