brown.cn
brown.cn

Reputation: 151

auto submit dropdown list in php

I want to create a dropdown list in a form and be able to submit/process it without pressing the submit button. I have

$cquery = 'SELECT * FROM tcat ORDER BY id ASC';
$cresult = mysql_query($cquery, $connection);
if(!$cresult){echo 'no result' . mysql_error();}
while($crow = mysql_fetch_array($cresult))
{echo $crow['cat'] . '</option><option>';}
?>

I would like to know if there is a way to make the default that is shown a different value aside the first or the last

Upvotes: 2

Views: 3540

Answers (3)

easteregg
easteregg

Reputation: 509

even simpler, this should work too!

<select onchange="submit();">
  <options ... >
</select>

Upvotes: 3

f.arcarese
f.arcarese

Reputation: 96

You have to use html and javascript and change your script to generate them accordingly:

<select name="aName" onChange="document.getElementById('yourFormId').submit();">
...
</select>

Upvotes: 2

user399666
user399666

Reputation: 19879

To submit a form without having the user press a submit button, you can use JavaScript:

document.getElementById("form_id").submit();

To set a default selected option, you can do this:

<option selected="selected">Category Name</option>

Note that PHP will not auto-submit a form for you as it is a server-side language.

Upvotes: 2

Related Questions