LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-23-2008, 11:36 AM   #1
DragonM15
Member
 
Registered: Sep 2003
Location: USA
Distribution: Slackware (Multiple Versions)
Posts: 455

Rep: Reputation: 31
Website with multiple dropdown menus


Ok, I know what you are thinking, "Oh, this is easy" BUT what I want to do might not be as easy as you think.

Here is what I want to do. I am making an html page that accepts input from users via a form text box, but I also want to have 2 dropdown menus. One will have a list of buildings, and one will have a list of types of products (This is for inventory). The HTML page will then send the variables from both the users text input and the users dropdown menu input to a php file that will then put that info into a mysql database. I have it working now with only ONE dropdown menu, but I need more than one. This is what I have so far.

insert.html:
Code:
<html>
<body>

<form action="inserttest.php" method="post"> <!-- name="myform"          onSubmit="return dropdown(this.typen)"> -->

Building Abbreviation: <input name="buiab" type="text" /><br />
Building Name: <select name="formVar1" onchange="document.myform.formVar1.value=this.value"><!-- <input name="build" type="text" /><br />-->
	<option value="">Select a Building</option>
	<option value="Art">Art</option>
	<option value="Cadet">Cadet</option>
	<option value="Computer Engineering Building">Computer Engineering Building</option>
</select><br />

Room Number: <input name="roomnum" type="text" /><br />
Type: <select onchange="document.myform.formVar.value=this.value">
	<option value="Display (Podium)">Display (Podium)</option>
	<option value="Computer (Podium)">Computer (Podium)</option>
	<option value="Computer (Lab)">Computer (Lab)</option>
	<option value="Display (Lab)">Display (Lab)</option>
</select><br />
Make: <input name="maken" type="text" /><br />
Model: <input name="modeln" type="text" /><br />
Serial: <input name="serialnum" type="text" /><br />
Special: <input name="specialnum" type="text" /><br />
Comments: <input name="commentst" type="text" /><br />
	
        <input type="hidden" name="formVar1" value="">
	<input type="hidden" name="formVar" value="">
	<input type="submit" value="Send form!">
</form>
</body>
</html>
insert.php:
Code:
<?php
include 'config.php';
include 'opendb.php';

$buildab = $_POST['buiab'];
$room = $_POST['roomnum'];
$make = $_POST['maken'];
$model = $_POST['modeln'];
$serial = $_POST['serialnum'];
$special = $_POST['specialnum'];
$comment = $_POST['commentst'];
$type = $_POST['formVar'];
$building = $_POST['formVar1'];

$query = "INSERT INTO $dbtable VALUES ('$buildab', '$building', '$room', '$type', '$make', '$model', '$serial', '$special', '$comment');";

echo $query, "<br />";

include 'closedb.php';
?>
Please note, my inserttest.php works perfectly fine if I have just text boxes in my inserttest.html, or if I only have 1 dropdown menu. I know if has something to do with my formVar and formVar1 in my inserttest.html. Please look at that first.

Thanks,
DragonM15

Last edited by DragonM15; 07-23-2008 at 11:37 AM.
 
Old 07-23-2008, 11:38 AM   #2
DragonM15
Member
 
Registered: Sep 2003
Location: USA
Distribution: Slackware (Multiple Versions)
Posts: 455

Original Poster
Rep: Reputation: 31
In my inserttest.php I also tried $_GET['formVar'] instead of $_POST Just a thought.

DragonM15
 
Old 07-23-2008, 11:56 AM   #3
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
And your problem is?

I presume that what you call a drop down menu is a combo box? Your HTML shows 2 combo boxes.

Your HTML also shows some javascript calls, when the javascript is not provided. Whatever your problem is will be in the javascript and not the HTML except insofar as the HTML is not calling the javascript correctly or some such.
 
Old 07-23-2008, 12:02 PM   #4
DragonM15
Member
 
Registered: Sep 2003
Location: USA
Distribution: Slackware (Multiple Versions)
Posts: 455

Original Poster
Rep: Reputation: 31
My problem is that the first text box (named formVar1) displays all the options, but when I pick one that variable is not sent to the php file when I click submit, while the one that is named formVar shows all the options, AND sends the variable to the php file as it should.

Sorry for my confusing description and probably source files as well.

DragonM15
 
Old 07-23-2008, 04:18 PM   #5
vladmihaisima
Member
 
Registered: Oct 2002
Location: Delft, Netherlands
Distribution: Gentoo
Posts: 196

Rep: Reputation: 33
I think the following solution is much cleaner (no hidden fields, no onchange, second select has a name):

Code:
<html>
<body>

<form action="inserttest.php" method="post"> 

Building Abbreviation: <input name="buiab" type="text" /><br />
Building Name: <select name="formVar1" >

	<option value="">Select a Building</option>
	<option value="Art">Art</option>
	<option value="Cadet">Cadet</option>
	<option value="Computer Engineering Building">Computer Engineering Building</option>
</select><br />

Room Number: <input name="roomnum" type="text" /><br />
Type: <select name="formVar">
	<option value="Display (Podium)">Display (Podium)</option>
	<option value="Computer (Podium)">Computer (Podium)</option>
	<option value="Computer (Lab)">Computer (Lab)</option>
	<option value="Display (Lab)">Display (Lab)</option>
</select><br />
Make: <input name="maken" type="text" /><br />
Model: <input name="modeln" type="text" /><br />
Serial: <input name="serialnum" type="text" /><br />
Special: <input name="specialnum" type="text" /><br />
Comments: <input name="commentst" type="text" /><br />

	<input type="submit" value="Send form!">
</form>
</body>
</html>
 
Old 07-28-2008, 11:27 AM   #6
DragonM15
Member
 
Registered: Sep 2003
Location: USA
Distribution: Slackware (Multiple Versions)
Posts: 455

Original Poster
Rep: Reputation: 31
Thanks vladmihaisima, that fixed my problem completely. Sorry for the delayed reply. Thanks again for your time.

DragonM15
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple website on Apache with User Directories Mr_Oz Red Hat 2 01-16-2006 07:20 AM
multiple website hosting matneyc Linux - Newbie 4 12-20-2004 03:21 PM
PHP Dropdown menu agallant Programming 1 06-10-2004 01:48 PM
where is majorcool list dropdown facility pudhiyavan Linux - Software 1 06-09-2004 03:28 AM
PHP code and DropDown Menu Gerardoj Programming 2 04-15-2004 02:53 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration