www.webdeveloper.com
Results 1 to 4 of 4

Thread: Am I doing hidden fields correctly? Because it will not show

  1. #1
    Join Date
    Dec 2005
    Posts
    14

    Am I doing hidden fields correctly? Because it will not show

    How do I create a hidden textfield in CGI PM, currently I am trying to use:

    Code:
    $q->hidden(-name=>'numQuestions',
                    -default=>$j);
    Although this does not show in the source code for the page.

    Any advice please? Thank you.

  2. #2
    Join Date
    Jan 2003
    Location
    USA
    Posts
    687
    Surely you mean hidden field.
    Code:
    $q->hidden(-name=>'numQuestions',-value=>$j);
    or
    Code:
    $q->hidden('numQuestions',$j);

  3. #3
    Join Date
    Dec 2005
    Posts
    14
    Still dosen't show, I cannot understand it.

    This is the code...the hidden tag is shown in bold

    Code:
    #!perl
    
    use Win32::ODBC;
    use CGI;
    
    my($db) = new Win32::ODBC("Exam");
    my($db2) = new Win32::ODBC("Exam");
    my($q) = new CGI;
    
    $db->Sql("SELECT * FROM questions ORDER BY questions.question;");
    
    print_header();
    
    
    create_questions();
    
    
    print_footer();
    
    # subroutines
    sub print_header {
    	print	$q->header(),
    			$q->start_html(-title=>'Exam test', -style=>{'src'=>'/style2.css'}),
    			$q->h1('Products'),
    			$q->br;
    }
    
    sub print_footer {	
    	print	$q->br,
    			$q->submit(-value=>'Submit'),
    			$q->reset(-value=>'Reset'),			
    			$q->end_html();
    }
    
    sub create_questions {
    	$q->startform(-action=>'exam_test2.pl');
    	$j = 1;
    	while($db->FetchRow()) {
    		%data = $db->DataHash();
    		print	"Ques $data{'questionID'}: $data{'question'} ";		
    		
    		$db2->Sql("SELECT questions.questionID, answers.answer, answers.correct FROM questions INNER JOIN answers ON questions.questionID = answers.questionID WHERE (((questions.questionID)=$data{'questionID'}));");
    		@answers = ();
    		$i = 0; # hold the element position in the answers list
    		while($db2->FetchRow()) {
    			%data = $db2->DataHash();	   
    			@answers[$i] = ($data{'answer'}); # push the answer into a list
    			$i++; # increment i to move forward one element in the list
    		}
    		$radioName = "answer" . $j;
    		print $q->radio_group(-name=>$radioName,
    							  -values=>[@answers]);
    
    		print $q->br;
    		$j++;
    	}
    	$q->hidden(-name=>'numQuestions',-value=>$j);
    	$q->endform(); # print a closing HTML </form> tag
    	$db->Close(); # close the connection to the ODBC
    Any ideas please? Thanks in advance!

  4. #4
    Join Date
    Jan 2003
    Location
    USA
    Posts
    687
    You need to print it.
    Code:
    print $q->hidden(-name=>'numQuestions',-value=>$j);
    print $q->end_form;
    Also, it should be...
    Code:
    $q->start_form

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles