Im working on a form that I need to break in sections. example form.cfm?section=A, form.cfm?section=B and form.cfm?section=C. When employee access form.cfm?section=A, form.cfm?section=B and C need to be disable only section A will available for user to add input. when section B is accessed by supervisor section A and C are disable and when section C is accessed by VP both A and B are disabled. Is there a way to do this with a JavaScrip function?

Thanks

Recommended Answers

All 2 Replies

if an input field is flagged disabled it will not post in a form submission.

So..

<form method="post" action="whatever.cfm">
<input name="a" type="text" />
<input name="b" type="text" disabled="disabled" />
<input name="c" type="text" disabled="disabled" />
<input type="submit" value="submit">
</form>

in javascript you can add or remove the attribute like so:

<script>

    var oFormElemb = document.forms[0].b.removeAttribute("disabled"); //enable element
    var oFormElema = document.forms[0].a.setAttribute("disabled", "disabled"); //disable element

</script>

the reason you need "disabled" to equald "disabled" is that in HTML all that is required is the word,
i.e. <input name="a" type="text" disabled /> however, in XHTML (and to make IE happy) you need it to equal something, therefore the standard is to make it equal disabled.

Hope that helps!

Ryan

Thanks

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.