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!

Recommended Answers

All 2 Replies

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()">

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.