Sandokan
Sandokan

Reputation: 849

How to submit a Form without using Submit event on Button.

I've made a simple calendar where you can select year and month through a dropdown list.

<form name=calenderselect method='post' action='calendar.php'>
<select name='month' id='month'>
<option>January</option>
<option>Februari</option>
<option>March</option>
....
</select>
<input type='submit' name='submit' value='Change' />
</form>

I find it abit annoying that you have to press the submit button every time you want to change month. I would like it to change the moment I click the month in the list.

Upvotes: 1

Views: 1836

Answers (6)

k102
k102

Reputation: 8079

here you are: <select name='month' id='month' onclick="this.form.submit()">

but i guess you really want to submit the form by onchange event.

Upvotes: 7

Jayyrus
Jayyrus

Reputation: 13051

<select name="month" id="month" onChange="document.getElementsByName('calenderselect')[0].submit()">

Upvotes: 0

code-red
code-red

Reputation: 306

if you are using jQuery..

$("#month").live('change',function() {
  $('form').submit();
});

this is useful if you want your html code clean.

Upvotes: 0

STT LCU
STT LCU

Reputation: 4330

You need a client-side event to achieve this (maybe "onChanged" for the select?)

1.listen for the event: add onChange="submitForm() to the select tag 2.define the submitForm() javascript function. It will basically be a simple form submit, nothing too long

done!

Look in google: "how to submit form through Javascript":

Upvotes: 0

Jeff Watkins
Jeff Watkins

Reputation: 6359

Given we can use JavaScript for this functionality (as mentioned in other answers), one has to wonder if we need submit at all for a change in a date control. Using AJAX to get back the required data for the selected date would be smoother as it would feature no page refresh.

Upvotes: 0

Edouard Moinard
Edouard Moinard

Reputation: 114

Add a javascript event on your select :

<select name="month" id="month" onChange="yourjsfunction()">

Upvotes: 3

Related Questions