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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I dynamically set the value of the cfinput “required” attribute 1

Status
Not open for further replies.

LyndonOHRC

Programmer
Sep 8, 2005
603
0
0
US
I would like to change the value of the attribute but if the element is <cfinput> the attribute is undefined.

I'm getting an 'object required" error trying to set the value so I am outputting the value.

Code:
<script type="text/javascript">
function DisplayForm()
{
	alert(document.forms["frmMain"].elements["Test"].required);
}
</script>
If the html is like this example "undefined" is returned to the alert function.
Code:
<cfform id="frmMain" name="frmMain">
	<cfinput type="Text" required="No" name="Test" value="Test" >
	<input type="button" value="Test" onclick="DisplayForm();" /> 
</cfform>
If the html is like this then the value of the attribute is returned to the alert function as I had expected.
Code:
<cfform id="frmMain" name="frmMain">
	<input type="Text" required="No" name="Test" value="Test" >
	<input type="button" value="Test" onclick="DisplayForm();" /> 
</cfform>

I'm confused because the required attribute seems to work correctly within the cfinput tag, I just don't know how to set it...

Any help appreciated.

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
I do not think you can dynamically make <cfinput> fields required that way. IIRC the javascript validation code, generated by CF, involves more than just a single attribute. It hooks into several javascript objects, arrays, etcetera. So even if you could set that attribute, it probably would not trigger the standard validation anyway.

One way to do it is to use OnValidate:

----------------------------------
 
I wound up using onSubmit and working out a nice solution.

Thanks.

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top