Skip to main content
Participant
August 24, 2010
Question

Conditional cfinput required

  • August 24, 2010
  • 2 replies
  • 1375 views

I am new to coldfusion. I created a cfform and I want to set a cfinput required to "yes" based on the previous radio selection. Here is a sample of the form I did.

<cfform action="index_act.cfm" method="post" name="scheduleChange" id="contest">

<p><cfinput type="radio" name="type" id="type" value="Meeting">Meeting</p>

<p><cfinput type="radio" name="type" id="type" value="Vacation">Vacation</p>

<p>Total day(s):<cfinput name="totalDay" type="text" id="totalDay" required="yes" message="Please enter Total days(s)"></p>

</cfform>

If the user select Meeting, the Total day(s) is not required.

If the user select Vacation, the Total day(s) is required.

Is this possible? Can I dod this with cfif? How? I am using MX. Any help is greatly appreciated.

    This topic has been closed for replies.

    2 replies

    ilssac
    Inspiring
    August 24, 2010

    As JR indicated.  CFML is just one piece of the puzzle of a modern webpage.  It is the piece that runs on the server and generates content to be sent to the client.  This content is often HTML, but can also be JavaScript, CSS, XML, JSON, PDF, and other formats. This all happens before a user sees anything in their browser.

    In the browser user inteface, you need to make use of a client side technology such as JavaScript.

    Participant
    August 24, 2010

    Thank you JR and ilssac. I will look into the javascript.

    I am also looking into disable and enable the cfinput based on the radio slelection for work around.

    Do you think this is something that need to be done with javascript?

    Inspiring
    August 24, 2010

    Yes. Logic that will need to execute on the client will need to be done using a client side technology such as Javascript.

    Inspiring
    August 24, 2010

    Using CFIF will not be effective.  CF tags execute on the server.  You will need to use Javascript to execute in the client's web browser.