/    Sign up×
Community /Pin to ProfileBookmark

Autosubmit works, then doesn’t

I am trying to understand a problem getting a form to autosubmit in response to an onchange event.

In both versions of the code below, the form should submit automatically if the user selects a new value on the option list or changes the first name. This version works, but does not have a way for the user to submit the form if javascript is not enabled:

[CODE]<html>
<body>
<p>Enter some text in the text fields below, and then press the “Submit” button to submit the form.</p>
<form id=”myForm” action=”somepage.php” method=”post”>
Firstname: <input type=”text” name=”firstname” size=”20″ onchange=”this.form.submit()”><br />
Lastname: <input type=”text” name=”lastname” size=”20″><br />
<select id=”email” onChange=”this.form.submit()”><option value=”1″>1</option><option value=”2″>2</option></select>
</form>
</body>[/CODE]

But this version only submits when the user clicks the submit button. The only difference is the addition of the submit button:

[CODE]<html>
<body>
<p>Enter some text in the text fields below, and then press the “Submit” button to submit the form.</p>
<form id=”myForm” action=”somepage.php” method=”post”>
Firstname: <input type=”text” name=”firstname” size=”20″ onchange=”this.form.submit()”><br />
Lastname: <input type=”text” name=”lastname” size=”20″><br />
<select id=”email” onChange=”this.form.submit()”><option value=”1″>1</option><option value=”2″>2</option></select>
<input id=”submit” type=”submit” name=”submit” value=”Submit”></form>
</body>[/CODE]

What am I doing wrong in the second example?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@bfuzzeqJun 05.2009 — in the second form your select dropdown does not have a name attribute. php request vars are tied to the name attribute not the id.
Copy linkTweet thisAlerts:
@jjackelauthorJun 05.2009 — in the second form your select dropdown does not have a name attribute. php request vars are tied to the name attribute not the id.[/QUOTE]

True, but fixing it does not alter the autosubmit behavior. I'm not concerned at this point with how the submission is handled. I just want the form to be submitted in response to onchange.
Copy linkTweet thisAlerts:
@jjackelauthorJun 07.2009 — I've worked around this issue by implementing AJAX. If the user has javascript on, AJAX updates the page automagically. If not, the user clicks "submit" to refresh the data.
×

Success!

Help @jjackel spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...