JavaScript: How to show error massage?

0

I would like to use javascript to check the number between two questions.

But I don’t know the script for don’t submit page, show error message, submit page.

Please kindly advise how to script it.

Below is the script that I tried to do (need help on bold text).

Thank you.

$SG(document).ready(function(){
var last = ‘[question(“value”),id=”33″]’;
var secondlast = ‘[question(“value”),id=”34″]’;
if(secondlast <= last)
{
//don’t submit page and show error message
}
else
{
//submit page
});
});

monthon asked
    0

    Just spent quite a while figuring out the same thing – here’s what I used, tweaked  from http://script.surveygizmo.com/help/article/link/calculate-age

     

    $SG(function(){

    $errortxt = ‘Lorem Ipsum’;

    //submit validation
    $(‘.sg-survey-form’).submit(function(e){

    if(

    ) {

    $(‘.sg-error-message’).text($errortxt).fadeIn(‘slow’);
    e.preventDefault();

    }
    }); //end submit validation
    });

    shoaibs answered
      • Thank you for your help.

        I think I can show the error message now. But, I can stop the page submission.
        Could you please advise on how to script the stop of page submission?

        Here is the update script.

        $SG(document).ready(function(){
        var last = ‘[question(“value”),id=”33″]’;
        var secondlast = ‘[question(“value”),id=”34″]’;
        $errortxt = ‘The number of ‘ + secondlast + ‘ must be more than ‘ + last;

        //submit validation
        $(‘.sg-survey-form’).submit(function(e){
        if(secondlast <= last)
        {
        //script for stopping the page submission.
        $('.sg-error-message').text($errortxt).fadeIn('slow');
        e.preventDefault();
        }

        });//end submit validation

        });

      ×

      Login

      Question stats

      • Active
      • Views527 times
      • Answers1 answer
      • Followers0 followers