473,473 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to create a Combobox in html form

10 New Member
Actually I have a CGI form which consists of
textfields and I need a combobox in which I can
enter my own data dynamically. May be it seems very
silly question but I am new to cgi-perl as well as
HTML so no idea what to do. Here is my form:

Expand|Select|Wrap|Line Numbers
  1. #!C:\perl\bin\perl.exe
  2.  
  3. use CGI;
  4. use CGI qw/:standard/;
  5. use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
  6. my $q = new CGI;
  7. use DBI;
  8. use CGI qw(:all);
  9. use strict;
  10. use warnings;
  11. print "Content-Type: text/html\n\n";
  12. print $q->header ( );
  13.  
  14. if ( $q->param("submit") )
  15. {
  16. process_form ( );
  17. }
  18. else
  19. {
  20. display_form ( );
  21. }
  22.  
  23.  
  24. sub process_form
  25. {
  26. if ( validate_form ( ) )
  27. {
  28. display_form ( );
  29. }
  30. }
  31.  
  32.  
  33. sub validate_form
  34. {
  35. my $User_Name = $q->param("User_Name");
  36. my $User_Password= $q->param("User_Password");
  37. my $User_Permission = $q->param("User_Permission");
  38. my $User_Department= join(", ",$q->param
  39. ("User_Department"));
  40. my $error_message = "";
  41. $error_message .= "Please enter your name<br/>" if
  42. ( !$User_Name );
  43. $error_message .= "Please enter your Password<br/>" 
  44. if( ! $User_Password );
  45. $error_message .= "Please Select a permission<br/>"
  46. if( !$User_Permission );
  47. $error_message .= "Please select atleast 1 
  48. department<br/>" if(!$User_Department);
  49.  
  50. if ( $error_message )
  51. {
  52. display_form (
  53. $error_message,$User_Name,$User_Password,$User_Per mission
  54. ,$User_Department);
  55. return 0;
  56. }
  57. else
  58. {
  59. my $dbh = DBI->connect
  60. ("dbi:SQLite:DEVICE.db","", "",{RaiseError => 1,
  61. AutoCommit =>
  62. 1 } );
  63. my $sql = "SELECT COUNT(UserName) FROM UsersList 
  64. WHERE UserName='$User_Name'";
  65. my $sth = $dbh->prepare($sql) or die("\n\nPREPARE 
  66. ERROR:\n\n$DBI::errstr");
  67. $sth->execute or die("\n\nQUERY 
  68. ERROR:\n\n$DBI::errstr");
  69. my ($n) = $dbh->selectrow_array($sth);
  70. $sth->finish();
  71. if ($n > 0) {
  72. print "Record Already Exists";
  73. }
  74. else {
  75. my $sql = "INSERT INTO UsersList 
  76. (UserName,Password,Permission,Department) VALUES 
  77. ('$User_Name ',' 
  78. $User_Password','$User_Permission','$User_Departme nt')";
  79. my $sth = $dbh->prepare($sql);
  80. $sth->execute;
  81. print "Record Added Successfully";
  82. $sth->finish();
  83. $dbh->commit or die $dbh->errstr;
  84. }
  85. $dbh->disconnect;
  86. }
  87. }
  88.  
  89. sub display_form
  90. {
  91. my $error_message = shift;
  92. my $User_Name = shift;
  93. my $User_Password = shift;
  94. my $User_Permission= shift;
  95. my $User_Department= shift;
  96.  
  97. my $User_Permission_Add_sel = $User_Permission 
  98. eq "Add" ? " checked" : "";
  99. my $User_Permission_Edit_sel =$User_Permission
  100. eq "Edit" ? " checked" : "";
  101. my $User_Permission_Delete_sel =$User_Permission
  102. eq "Delete" ? " checked" : "";
  103. my $User_Permission_View_sel =$User_Permission
  104. eq "View" ? " checked" : "";
  105.  
  106. my $User_Department_html = "";
  107. my $dbh = DBI->connect
  108. ("dbi:SQLite:DEVICE.db","", "",{RaiseError => 1,
  109. AutoCommit =>
  110. 1 } );
  111. my $sql = "select DepartmentName from Departments 
  112. order by DepartmentName";
  113. my $sth = $dbh->prepare($sql);
  114. $sth->execute() ;
  115.  
  116. while (my $User_Department_option= $sth- 
  117. >fetchrow_array)
  118. {
  119. $User_Department_html.= "<option
  120. value=\"$User_Department_option\"";
  121. $User_Department_html.= " selected" if (
  122. $User_Department_option eq
  123. $User_Department );
  124.  
  125. $User_Department_html.= ">$User_Department_option</option
  126. >";
  127. }
  128. $sth->finish();
  129. $dbh->commit or die $dbh->errstr;
  130. print <<END_HTML;
  131. <html>
  132. <head><title>Form Validation</title></head>
  133. <body>
  134.  
  135. <form action="AddUser.cgi" method="post">
  136. <input type="hidden" name="submit" value="Submit">
  137.  
  138. <p>$error_message</p>
  139.  
  140.  
  141. <TABLE BORDER="1" align="center">
  142. <TR>
  143. <TD>Name</TD>
  144. <TD> <input type="text" name="User_Name" 
  145. value="$User_Name"></TD>
  146. </TR>
  147.  
  148. <TR>
  149. <TD>Password</TD>
  150. <TD colspan="2"><input type="password"
  151. name="User_Password" value="$User_Password" 
  152. size="20" maxlength="15" /></TD>
  153.  
  154. </TR>
  155. <TR>
  156. <TD>Role</TD>
  157. <TD>"HERE I NEED A COMBOBOX"</TD>
  158. </TR>
  159.  
  160. <TR>
  161. <TD>Permission</TD>
  162. <TD><input type="radio" name="User_Permission" 
  163. value="Add"$User_Permission_Add_sel>Add<input 
  164. type="radio" name="User_Permission"
  165. value="Edit"$User_Permission_Edit_sel>Edit<input 
  166. type="radio" 
  167. name="User_Permission"
  168. value="Delete"$User_Permission_Delete_sel>Delete<i nput
  169. type="radio" name="User_Permission" 
  170. value="View"$User_Permission_View_sel>View</TD>
  171. </TR>
  172.  
  173. <TR>
  174. <TD>Department</TD>
  175. <TD colspan="2"> <select name="User_Department" 
  176. MULTIPLE
  177. SIZE=4>$User_Department_html</select></TD>
  178.  
  179. </TR>
  180. </TR>
  181. <TR>
  182. <TD align="center" colspan="2">
  183. <input type="submit" name="submit" value="ADD">
  184. </TD>
  185. </TR>
  186. </TABLE
  187. </form>
  188.  
  189. </body></html>
  190. END_HTML
  191.  
  192. }
Sep 13 '10 #1
1 2626
numberwhun
3,509 Recognized Expert Moderator Specialist
First, you really need to learn to enclose your code in code tags. After even as little as 6 posts you should have been instructed to do this before. Please be sure and do it in the future.

As for the combo box, you should really learn some HTML and learn how to add it. You say you don't know any, then can we assume that you got this code from elsewhere?

Regards,

Jeff
Sep 14 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Matt | last post by:
I have a html form, and I want to transform html form data to xml string. Given XSD (xml schema), how to transform the form data to xml string?
0
by: Adam Retter | last post by:
Hi Guys, I have a need to create a html form based on my schema. I initially decided to do this using xql, have got some way but am finding this difficult (it may be as I am very new to xql)....
5
by: ojvm | last post by:
ok. thanks again for the time spend reading this. this code adds 2 controls in html form but it places in top of the form. i want this control1 control2 control1 control2 control1 ...
2
by: Shahid | last post by:
Hi, I have an xml document, example below. I would like to create an HTML form dynamically so all I would do is change the XML form in case a different version comes. I am relatively new...
2
by: Mark | last post by:
Hi all, I have a WYSIWYG editor which allows people to insert a form into a page. This information is stored in a database and at run-time is displayed inside a content placeholder (I'm using...
5
by: patricksabourin | last post by:
On my site, I have 2 methods of displaying my data: 1) HTML form with select-option element. (Jump to different page when clicking "Go" button" 2) HTML table with a hyperlink. What I would...
1
by: John Wolff | last post by:
I’m trying to upload a file to a Web Service. I have to submit the file using a standard HTML form with the <input type=“file” /tag. Ultimately, we are submitting the file from a Flash 8...
0
by: bp_jobemail | last post by:
I'm trying to use PHP to wrap the output of an HTML form before it goes into a precompiled C cgi script. Essentially, the company that I work for uses a purchased precompiled c program for their...
1
by: Lelu | last post by:
Hi, My HTML form is generating some blank email responses; does anyone see anything wrong with the scripts?: function isFormVarExcluded(thisForm, strToCheck) { var strExcludeVars =...
1
AdminCyn
by: AdminCyn | last post by:
I am working on a project to update our website functionality; mainly I am suppose to create an HTML form for prospective tenants to fill out and submit via email; I have the html form done and...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.