Trium918 Posted April 2, 2007 Share Posted April 2, 2007 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>"; Quote Link to comment Share on other sites More sharing options...
Waldir Posted April 2, 2007 Share Posted April 2, 2007 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"; } Quote Link to comment Share on other sites More sharing options...
emehrkay Posted April 2, 2007 Share Posted April 2, 2007 well that would require some javascript code <script type="text/javascript"> function dropChnge(){ var drop = document.getElementById('dropDownId'); drop.change = function(){ document.getElementById('formId).submit(); } } </script> Quote Link to comment Share on other sites More sharing options...
trq Posted April 2, 2007 Share Posted April 2, 2007 You can use Javascript's onChange() method to automatically submit the form when an item has been selected. Ask in the Javascript forum if your unsure of the how. Quote Link to comment Share on other sites More sharing options...
Waldir Posted April 2, 2007 Share Posted April 2, 2007 my bad i missunderstod you, just change your form to this <select name=\"searchtype\" onChange="form.submit()"> and get rid of your button, *not tested Quote Link to comment Share on other sites More sharing options...
Trium918 Posted April 2, 2007 Author Share Posted April 2, 2007 Thanks. I got it working!!! Quote Link to comment Share on other sites More sharing options...
Trium918 Posted April 2, 2007 Author Share Posted April 2, 2007 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. Quote Link to comment Share on other sites More sharing options...
Trium918 Posted April 2, 2007 Author Share Posted April 2, 2007 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? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 2, 2007 Share Posted April 2, 2007 No. Why do you want to remove the submit button anyway? Ken Quote Link to comment Share on other sites More sharing options...
Trium918 Posted April 2, 2007 Author Share Posted April 2, 2007 It does't look right on my page. Quote Link to comment Share on other sites More sharing options...
Trium918 Posted April 2, 2007 Author Share Posted April 2, 2007 Is there away to tell if javascript is turned off and if so display the submit button? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 2, 2007 Share Posted April 2, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.