Deepzone Posted February 22, 2013 Share Posted February 22, 2013 Hi there, Is it possible to do a postback (without click on a button) as soon as user selected a value from a dropdown list? Thanks. Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 22, 2013 Share Posted February 22, 2013 Yes, with Javascript. Quote Link to comment Share on other sites More sharing options...
Deepzone Posted February 22, 2013 Author Share Posted February 22, 2013 (edited) Hi there, Is it possible to do a postback (without click on a button) as soon as user selected a value from a dropdown list? Thanks. Is this the only way? What happened if javascript is disabled? Edited February 22, 2013 by Deepzone Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 22, 2013 Share Posted February 22, 2013 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. Quote Link to comment Share on other sites More sharing options...
Deepzone Posted February 22, 2013 Author Share Posted February 22, 2013 (edited) Yes, with Javascript. okay, I decided to use javascript. Edited February 22, 2013 by Deepzone 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.