#1
  1. No Profile Picture
    SWAT
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Location
    baltimore
    Posts
    5
    Rep Power
    0

    Cold Fusion Forms


    Hey,
    I am creating a form in cold fusion, that will connect to the database. The form will work in this fashion: Question 1, if you ansered yes, then go to next question. If answer is no, then prompt a new field to explain why. This field appears when the user clicks "no". This is how each of the questions are set up. I'm not quite sure how to generate that new field when the "no" box is clicked. Any suggestions? Thanks
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    11
    Rep Power
    0

    Talking JavaScript is the answer with hidden fields on the next page's form


    What you will do is put some JavaScript in the <head></head> tags of your page.

    I have written the page for you in clean HTML and JavaScript, email me at support@ColdFusionCart.com if you have any more questions, but this page is simply, a little fancy, will run in IE and Netscape and can be adjusted very easily for your project:

    I wrote you this HTML page and here's what it does:

    1) User comes to the page and gets asked a question.

    2) If he picks nothing, then we give him a warning telling him that he better select an answer, whether Yes or No.

    3) IF he picks Yes, then we let him go on his merry way to the next page (next_page.cfm)

    4) IF he picks No, then we give him a warning, telling him he had better give us a reason why he is picking No. Then all the sudden a text box will magically appear on the screen and tell him that he can enter his answer inside of it.

    5) IF he picks No, then he CANNOT leave the page until he gives us a reason why he picked No.

    I have debugged this for you and it works beautifully:

    <html>
    <head>

    <!----paste this JavaScript code into your <head></head> tags---->
    <script language="JavaScript">

    function checkIfNo(){

    //if he picks nothing, then let's set everything back to null values
    if (document.myForm.someFormField.value == '')

    {
    myDiv.style.visibility = 'hidden';
    }

    //if he picks No, then open the text box and un-disable it because we are going to FORCE him to tell us why he ain't using it
    if (document.myForm.someFormField.value == 'No')

    {
    alert('You selected No, so please tell us why you are selecting No as your answer!');
    myDiv.style.visibility = 'visible';
    }

    //if he picks Yes, then hide the text box because he can leave freely as he wishes to the next page
    if (document.myForm.someFormField.value == 'Yes')

    {
    myDiv.style.visibility='hidden';
    }

    }

    function askMeWhy(){

    //first make sure the value of the drop-down menu is NOT NULL
    if (document.myForm.someFormField.value == '')

    {
    //give the message that he forgot to answer the question
    alert('What about answering the question in the first place?!?');

    //put the mouse in the field for him to hold his hand a little through the forms process
    document.myForm.someFormField.focus();

    //don't let him go anywhere yet becuase he hasn't got his facts straight
    return false;
    }

    //this JavaScript function can be used to make sure that if the user clicks "No", then he MUST fill in an answer
    //in the text box in the form.....only then can he submit the form to the next page

    //if "No" button is checked, then we will un-disable the textbox, tell him to type something in it, and then NOT let him
    //leave the page until he has filled in the text box with the reason why he picked "No"

    if (myDiv.style.visibility == 'visible')

    {

    if (myForm.myTextBox.value == '')

    {
    alert('Enter your Reason Here!');
    myForm.myTextBox.focus();
    return false;
    }

    }

    }

    </script>

    </head>

    <body>

    <p><strong>Hello and welcome to this form - fill it out or else!</strong>

    <p>

    <form action="next_page.cfm" method="post" name="myForm" onSubmit="return askMeWhy();">

    <table width="100%" cellpadding="2" cellspacing="2" border="0">
    <tr>
    <td width="32%" valign="top">

    <p>Do you need a Cold Fusion Shopping Cart?

    <p>

    <!----here are your radio buttons, set the default to Yes if you want by saying and optional 'checked' in its field---->
    <select name="someFormField" onChange="checkIfNo();">
    <option value="">Select on the these answers</option>
    <option value="Yes">Yes, I need a Cold Fusion Shopping Cart</option>
    <option value="No">No, I don't need a Cold Fusion Shopping Cart</option>
    </select>

    </td>
    <td width="68%" valign="top">

    <!----you have to put this one inside a "div" so you can hide it when they select yes but shove it in their face when they select No---->
    <div id="myDiv" style="position:absolute; visibility:hidden;">

    <p>You selected <strong>"No"</strong> as your answer, please fill in your reason here:
    <br><textarea cols="55" rows="5" name="myTextBox"></textarea>

    </div>

    </td>
    </tr>
    </table>

    <p><input type="submit" value="Go To Next Page!">

    </form>

    </body>
    </html>

    Marc
    Software Engineer
    Cold Fusion Shopping Cart
    support@ColdFusionCart.com
    www.ColdFusionCart.com
  4. #3
  5. No Profile Picture
    SWAT
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Location
    baltimore
    Posts
    5
    Rep Power
    0
    thanks! i'll check it out and let ya know if I have any questions. I appreciate your help!
  6. #4
  7. No Profile Picture
    SWAT
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Location
    baltimore
    Posts
    5
    Rep Power
    0

    Question


    I applied the code and it works great. I'm not that formiliar with javascript, so I am having some trouble having multiple questions on the page. I thought I was doing it right but apparently not. Can you please help? I appreciate it. Thanks!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    11
    Rep Power
    0

    Sure thing - just email me your code and I will help you out


    Sure thing - just email me your code @ support@ColdFusionCart.com and I will be happy to take a look.
  10. #6
  11. No Profile Picture
    SWAT
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Location
    baltimore
    Posts
    5
    Rep Power
    0
    thanks! I emailed ya the code.

    Originally Posted by ColdFusionCart
    Sure thing - just email me your code @ support@ColdFusionCart.com and I will be happy to take a look.

IMN logo majestic logo threadwatch logo seochat tools logo