Radio button certain answer required?

jkerr 01 Dec, 2010
Hi all, sorry about the horrible thread title.

I have a list of questions that have either a yes or a no answer. I was wondering if there is a way to have a message appear if the user selects no.

For example

If the questions was "Do you have a dog?" and the user selected no, then text would appear saying "Click this link to buy a dog" and the submit button wouldn't work.


I haven't explained very well so let me know if you need me to describe better.

Cheers
Jamie
GreyHead 01 Dec, 2010
Hi Jamie,

There's nothing built into ChronoForms to do that but you can code it in JavaScript without too much difficulty.

Bob
jkerr 02 Dec, 2010
Hi Bob

I thought I would need to code it in javascript (using an if statement I would imagine). Sadly, I haven't a clue how to code (apart from a tiny bit of VB6 years ago). Any chance you could give me a guideline on how to code it?

Jamie
jkerr 02 Dec, 2010
Ok I have been messing around and have managed to get it working.

Code I am using is this
    window.onload = function()

    {

        var a = document.getElementById('radio01');
        var b = document.getElementById('radio11');
        var c = document.getElementById('radio21');

        a.onclick = message1;
        b.onclick = message2;
        c.onclick = message3;

    }

    function message1() 
    {
        alert('This is message 1');
    }

  function message2() 
    {
        alert('This is message 2');
    }

  function message3() 
    {
        alert('This is message 3');
    }


Now I was wondering, how do I disable the submit button when one of these buttons are still checked?
GreyHead 11 Dec, 2010
Hi jkerr,

Try
if ( $('radio01').checked || $('radio02').checked || $('radio03').checked ) {
  $('submit').disabled = true; 
} else {
  $('submit').disabled = false; 
}

Bob
This topic is locked and no more replies can be posted.