• Hi,
    Maybe for someone this script will be helpful.

    It’s using jquery in compatibility mode ($j) to verify is user fill all required fields. In question needs to be <span> tag with “*”. Now is working only with radio input and text area.

    var reqQuestion = new Array();
    		var reqOK=0;
    
    		$j('#survey-action-button').attr('disabled','disabled');
    		$j('<p></p>').insertBefore('#survey-action-button').text('Please fill all requied fileds').addClass('infoMes');
    
    		$j('.survey-question').each(function(){
    			if($j(this).find('span').text()=='*'){
    				$j(this).addClass('req');
    			}
    		});
    
    		function checkSurvey(){
    			reqOK=0;
    			$j('.req').each(function(i){
    				reqQuestion[i]=0;
    
    				if($j(this).find('.user-answer').length>0){
    					var valtext = $j(this).find('.user-answer').val();
    					if(valtext!=''){
    						reqQuestion[i]=1;
    
    					}
    					else reqQuestion[i]=0;
    				}
    				else {
    					if($j(this).find('.answer').is(':checked')){
    						reqQuestion[i]=1;
    					}
    					else reqQuestion[i]=0;
    				}
    
    				reqOK+=reqQuestion[i];
    			});
    			if(reqOK==reqQuestion.length){
    				$j('#survey-action-button').removeAttr('disabled');
    				$j('.infoMes').text('');
    			}
    			else{
    				$j('#survey-action-button').attr('disabled','disabled');
    				$j('.infoMes').text('Please fill all requied fileds');
    			}
    		}
    
    		$j('.answer').change(function(){
    			checkSurvey();
    		});
    		$j('.user-answer').keyup(function(){
    			checkSurvey();
    		});

    http://wordpress.org/extend/plugins/surveys/

Viewing 1 replies (of 1 total)
  • Hi Cryptic,

    I’m trying to include your script, but I can’t get it to work. I placed your script in script.js and added a <span>*</span> in the question-text of a radio-input question.

    All that happens is that there is now a next-button below my survey (I had all the questions on one page, so the button wasn’t there before), but if I leave the required question empty, I don’t get a warning that an answer is required.
    It doesn’t matter if I use the “next” button or the “submit survey” button.

    Any ideas?

Viewing 1 replies (of 1 total)

The topic ‘[Plugin: Surveys] Required fileds script’ is closed to new replies.