PDA

View Full Version : checkbox in a dropdown menu?



jes___per
03-03-2009, 07:50 AM
Hi,

can u have a checkbox in a dropdown meny?

and if whoe can u do it?

Snookerman
03-03-2009, 04:14 PM
I'm not sure I understand what you mean. If you mean that you can choose multiple options from a dropdown, you can use multiple, e.g.:

<select multiple="multiple">
<option>One</option>
<option>Two</option>
<option>Three</option>
<option>Four</option>
</select>
Now several options can be selected at the same time. If this isn't what you want, please try to be more specific.

jes___per
03-04-2009, 07:41 AM
thx that is exacly what i ment

cheers

jes___per
03-04-2009, 08:28 AM
but i cant gfet it to work:/

Snookerman
03-04-2009, 08:52 AM
Can you post a link to your site or the code you are using? We can't really help you without anything.

jes___per
03-04-2009, 10:18 AM
<html>
<head>

<title>Min Databas</title>

</head></br>

<body>
<center>
<img src="Earth.gif" alt="Earth"></br>
</br>
<form method="post" action="test.php">
<b>Förnamn:</b> <input type="text" size="10" maxlength="40" name="för"></br>
<b>Efternam:</b> <input type="efter" size="10" maxlength="10" name="efter"></br>
</br>
</br>
<b>Ställ din Fråga:</br> </b><input type="checkbox" name="Select2"> Fler Select alternativ</br>
</br>
</br>
<b>Select:</b>
<select name="Select">
<option>Välj</option>
<option value = "*">Alla (*)</option>
<option>Förnamn</option>
<option>Efternamn</option>
<option>Adress</option>
<option>Telefon</option>
<option>E-post</option>
<option>Personnummer</option>
</select>
<select name="Select2">
<option value = "">Välj</option>
<option>Förnamn</option>
<option>Efternamn</option>
<option>Adress</option>
<option>Telefon</option>
<option>E-post</option>
<option>Personnummer</option>
</select>
<b>From:</b>
<select name="From">
<option>Välj</option>
<option>DB</option>
<option>DB2</option>
</select>
<b>Where:</b>
<select name="Where">
<option value = "">Välj</option>
<option value = "*">Alla (*)</option>
<option>Förnamn</option>
<option>Efternamn</option>
<option>Adress</option>
<option>Telefon</option>
<option>E-post</option>
<option>Personnummer</option>
</select>
<select name="Where2">
<option value = "">Välj</option>
<option value = "=">= Equal</option>
<option value = ">">> Greater than</option>
<option value = "<">< Less then</option>
<option value = ">=">>= Greater than or equal</option>
<option value = "<="><= Less than or eaual</option>
<option value = "<>"><> Not equal to</option>
<option value = "like">LIKE</option>
</select>
<b>Optional:</b>
<input type="text" size="30" name="Optional"></br>
</br>
</br>
<input type = "submit" value = "Skicka Fråga">
</from>
</body>
</html>


<html>
<head>

<title>Test</title>

</head></br>

<body>
<?php
mysql_connect("localhost", "Sara", "sara123") or die('Du är inte välkomen här!!!');
mysql_select_db('test');
// add the new information into the database
/* mysql_query("INSERT INTO info (Förnamn, Efternamn, Telefonnr)
VALUES('$_POST[Förnamn]','$_POST[Efternamn]','$_POST[Telefonnr]') ")
or die(mysql_error());
echo "success in database entry.</br>";
echo "<br />";
echo "<a href=\"Inmatning.php\">Click here to return to the form page.</a>";
*/
$Select=$_POST['Select'];
$Select2=$_POST['Select2'];
$From=$_POST['From'];
$Where=$_POST['Where'];
$Where2=$_POST['Where2'];
$Optional=$_POST['Optional'];

if ($Select==$_POST['Select'] && $Select2==$_POST['Select2'] && $From==$_POST['From'] && $Where==$_POST['Where'] && $Where2==$_POST['Where2'] && $Optional==$_POST['Optional'])
{
echo "Data ur databas $From med följande SQL kod:", "</p>";
echo "<b>Select</b> $Select, $Select2 <b>From</b> $From <b>Where</b> $Where $Where2 $Optional";
// Make a MySQL Connection
$query = "SELECT $Select, $Select2 FROM $From WHERE $Where $Where2 '$Optional' ";

$result = mysql_query($query) or die(mysql_error());
echo "<table border =1> </br>";
if ($Select == '*')
{
echo "<tr>
<th>Förnamn</th>
<th>Efternamn</th>
<th>Adress</th>
<th>Telefon</th>
<th>E-post</th>
<th>Personnummer</th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>".
"<td>".$row['Förnamn']."</td>".
"<td>".$row['Efternamn']."</td>".
"<td>".$row['Adress']."</td>".
"<td>".$row['Telefon']."</td>".
"<td>".$row['E-post']."</td>".
"<td>".$row['Personnummer']."</td>".
"</tr>";
}
echo "</table>";
}
else
{
echo "<tr>
<th>$Select</th>
<th>$Select2</th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>".
"<td>".$row[$Select]."</td>".
"<td>".$row[$Select2]."</td>".
"</tr>";
}
echo "</table>";
}
}
else if ($Select==$_POST['Select'] && $From==$_POST['From'])
{
echo "Data ur databas $From med följande SQL kod:", "</p>";
echo "<b>Select</b> $Select <b>From</b> $From";
// Make a MySQL Connection
$query = "SELECT $Select FROM $From";

$result = mysql_query($query) or die(mysql_error());
echo "<table border =1> </br>";
echo "<tr>
<th>$Select</th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>".
"<td>".$row[$Select]."</td>".
"</tr>";
}
echo "</table>";
}
else
{
echo "...";
}
?>
</body>
</html>

Snookerman
03-04-2009, 10:22 AM
You didn't use multiple, add the highlighted to the dropdowns you want:

<select multiple="multiple">
<option>One</option>
<option>Two</option>
<option>Three</option>
<option>Four</option>
</select>

Good luck!

Nile
03-04-2009, 01:07 PM
One thing you may want know about multiple, is that it can select multiple items. I don't know if thats what you want, so just letting you aware. ;)

jes___per
03-05-2009, 08:10 AM
ok but i cant get it to work:(

Snookerman
03-05-2009, 02:02 PM
Please post a link to the page on your site that contains the problematic script or attach your code so we can check it out and help you.

codeexploiter
03-06-2009, 09:37 AM
ok but i cant get it to work:(

The way you have used the select list elements in the furnished code makes the user to select only one option in the select lists.

If you want to allow the user to select multiple item you have to add a


multiple="multiple"

attribute on the select list element markup on which you want to allow the users to select multiple items.