Jump to content

Auto Postback if dropdown list is selected


Deepzone

Recommended Posts

Is this the only way? What happened if javascription is disabled?

 

Then it doesn't work. PHP code is executed server-side, Javascript is executed client-side. I suppose you could do it with an applet or some other client-side plug-in that would require the user to install - but that's worse than relying on Javascript.

 

Using Javascript to add functionality such as this is the best approach. But, if you want your application to also work without Javascript then you need to build it in such a way that the page will work either way: e.g. unobtrusive Javascript. In this approach you build the page first to work without Javascript. Then you add Javascript on top of that code so that if JS is disabled it will gracefully fall back to the version that will work without JS.

 

In this case you build your form such that the user has to make a selection using the dropdown and then click a submit button. Then you do two things. 1) And an onchange event to the drop-down to auto-submit the form. 2) Add an onload event to the page to remove/hide the submit button.

 

The result is that if JS is enabled the submit button won't display and when the user selects a dropdown value the page automatically submits. If the user does not have JS enabled then the user can select a value and then click the submit button.

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.