DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   ColdFusion (http://www.daniweb.com/forums/forum19.html)
-   -   Automate undisabled a “submit button”? (http://www.daniweb.com/forums/thread117641.html)

Hercf Apr 5th, 2008 6:10 pm
Automate undisabled a “submit button”?
 
Help!
Hi, everbody!
I have this problem:
There is a “textbox” and a “submit” button.
“Submit button” is disabled until something is written within “text box”. I am not able to do this switch. Could anybody help me?
Here you are the code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<cfform name="form1" id="form1" method="post" action="">
<cfinput type="text" name="Text" id="Text">
<cfinput type="submit" name="submit" disabled="disabled" id="submit" value="Submit">
</cfform>
</body>
</html>
Thank you!

cmhampton Apr 10th, 2008 5:00 pm
Re: Automate undisabled a “submit button”?
 
You need to use a javascript function for this:

function ChangeButtonStatus()
{
    if (document.getElementById("Text").value.length > 0)
    {
      document.getElementById("submit").disabled = false;
    }
    else
    {
      document.getElementById("submit").disabled = true;
    }
}

Then in your form, add an OnBlur event to the textbox:

  <cfinput type="text" name="Text" id="Text" OnBlur="ChangeButtonStatus()">

jamba Apr 30th, 2008 12:13 pm
Re: Automate undisabled a “submit button”?
 
cmhamton has provided the solution - but just to expand:
So as to open the function to any form and any form objects:

function toggleObj(frmFld,frmBtn) 
{
//frmFld = the Form Field to check for value
//frmBtn = the Form Button to disable/enable

if(frmFld.value.length>0)
{
frmBtn.disabled=false;
}
else
{
frmBtn.disabled=true;
}
}

sorry - haven't actually tested this...


All times are GMT -4. The time now is 10:58 pm.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC