Jump to content

[SOLVED] Automatically


Trium918

Recommended Posts

Is the away to automatically select a item

from a Drown Down Menu with out have to

use a Submit button?

 

$query2 = "SELECT DISTINCT sponsor FROM people";
$result2 = mysql_query($query2);
$num_results2 = mysql_num_rows($result2);

echo "<form method=post>";
echo "<select name=\"searchtype\" >
<option>Sponsor</option>";
for ($i = 0; $i < $num_results2; $i++) {
$row = mysql_fetch_array($result2);
echo "<option value=\"$row[sponsor]\">$row[sponsor]</option>\n";
} 
echo "</select>";
echo "<input type=\"submit\" value=\"Submit\" />";  //Trying to get ride of this
echo "</form>";

Link to comment
Share on other sites

yes using SELECTED witch item you want to select? if u know the name of it you can do something like

 

if($row[name] == "name u want") {

echo "<option value=\"$row[sponsor]\" SELECTED>$row[sponsor]</option>\n";

} else {

echo "<option value=\"$row[sponsor]\">$row[sponsor]</option>\n";

}

Link to comment
Share on other sites

If the user does not have a Javascript enabled browser or the user wants to choose the default option, then this method will not work.  Because either of those cases are common, the form should contain a SUBMIT button that forces the page to be submitted.

 

Is there away around this.

Link to comment
Share on other sites

If the user does not have a Javascript enabled browser or the user wants to choose the default option, then this method will not work.  Because either of those cases are common, the form should contain a SUBMIT button that forces the page to be submitted.

 

Is there away around this.

 

Any Ideas?

Link to comment
Share on other sites

You can change the look & feel of the submit button by using CSS. That way you can change it to match your site.

 

Try this example (which really belongs in the CSS area):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>
<head>
<title></title>
<style type="text/css">
.sub1 {
	border: none;
	background-color: transparent;
	color: Red;
	cursor: pointer;
}

.sub1:hover {
	background-color: Red;
	color: Black;
	font-weight: bold;
}

</style>
</head>

<body>
<form method="post">
<input type="text" name="test">
<input class="sub1" type="submit" name="submit" value="Test">
</form>


</body>
</html>

 

Ken

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.