Dynamically diplaying form fields after selectuing data from drop down

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Chittaranjan
    New Member
    • Sep 2006
    • 51

    Dynamically diplaying form fields after selectuing data from drop down

    Hi All,

    I have a problem and hope I can get the better solution from here.

    I have a form written in HTML and I need to write that in perl so the main problem I am facing is that I need to generate some fields according the data I will select from the drop down list so basically I have drop down list which will ask for the number of students information I want to enter and after selecting a value from the number of students drop down it suppose to display that much set of First name, Last name, Phone number etc. So how can I post back the data to the same form in PERL script I can't able to know. I know we can do in Java but for PERL I do not know. So please help me I will be grateful to you all. I will be waiting for the replies.

    Thanks,
    Chittaranjan :)
    Last edited by Chittaranjan; Nov 20 '06, 12:51 PM. Reason: spelling mistake
  • GunnarH
    New Member
    • Nov 2006
    • 83

    #2
    Basically you can do something like this:
    Code:
    use CGI;
    my $cgi = CGI->new;
    
    print $cgi->header;
    print qq|<form method="post">\n|;
    
    if ( $cgi->param('number') ) {
    
    	for ( 1 .. $cgi->param('number') ) {
    		print <<REC;
    <p>First name $_:<br><input name="first_$_">
    <p>Last name $_:<br><input name="last_$_">
    <p>Phone number $_:<br><input name="phone_$_">
    <hr>
    REC
    	}
    
    } else {
    
    	print <<NUM;
    <p>Select number of records:<br>
    <select name="number">
    <option selected>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    </select>
    NUM
    
    }
    
    print qq|<p><input type="submit">\n</form>\n|;

    Comment

    • Chittaranjan
      New Member
      • Sep 2006
      • 51

      #3
      Originally posted by GunnarH
      Basically you can do something like this:
      Code:
      use CGI;
      my $cgi = CGI->new;
      
      print $cgi->header;
      print qq|<form method="post">\n|;
      
      if ( $cgi->param('number') ) {
      
      	for ( 1 .. $cgi->param('number') ) {
      		print <<REC;
      <p>First name $_:<br><input name="first_$_">
      <p>Last name $_:<br><input name="last_$_">
      <p>Phone number $_:<br><input name="phone_$_">
      <hr>
      REC
      	}
      
      } else {
      
      	print <<NUM;
      <p>Select number of records:<br>
      <select name="number">
      <option selected>1</option>
      <option>2</option>
      <option>3</option>
      <option>4</option>
      <option>5</option>
      </select>
      NUM
      
      }
      
      print qq|<p><input type="submit">\n</form>\n|;
      Thanks GunnarH,

      It works great. you are unbelievable, nice way to the solution.

      Thanks again For your great help,
      Chittaranjan :)

      Comment

      Working...