Quizzer::Element::Web::Select - A select box on a form


Quizzer documentation Contained in the Quizzer distribution.

Index


Code Index:

NAME

Top

Quizzer::Element::Web::Select - A select box on a form

DESCRIPTION

Top

This element handles a select box on a web form.

METHODS

Top

show

Generates and returns html representing the select box.

process

This gets called once the user has entered a value. It is passed the value they entered. It saves the value in the associated Question.


Quizzer documentation Contained in the Quizzer distribution.
#!/usr/bin/perl -w

package Quizzer::Element::Web::Select;
use strict;
use Quizzer::Element::Select;
use vars qw(@ISA);
@ISA=qw(Quizzer::Element::Select);

my $VERSION='0.01';

sub show {
	my $this=shift;

	$_=$this->question->extended_description;
	s/\n/\n<br>\n/g;
	$_.="\n<p>\n";

	my $default='';
	$default=$this->question->value if defined $this->question->value;
	my $id=$this->id;
	$_.="<b>".$this->question->description."</b>\n<select name=\"$id\">\n";
	my $c=0;
	foreach my $x ($this->question->choices_split) {
		if ($x ne $default) {
			$_.="<option value=".$c++.">$x\n";
		}
		else {
			$_.="<option value=".$c++." selected>$x\n";
		}
	}
	$_.="</select>\n";
	
	return $_;
}

sub process {
	my $this=shift;
	my $value=shift;

	my @choices=$this->question->choices_split;
	return $choices[$value];
}

1