7

Hi the question is pretty simple.

<select name="justanumber">
    <option value="1" selected="selected">1</option>
    <option value="2"></option>
</select>

when selected value is changed i have to do a form post. But the problem is to do this WITHOUT javascript.

I'm not sure is it possible to do that, the best result i have archived is submit form using label for.

Roman Kupin
  • 232
  • 1
  • 4
  • 12

7 Answers7

4

No, that is not possible without using client script.

I suggest that you use script for how you want it to work normally, and supply a submit button as a backup for those who can't use script.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
  • I can't use script. It's just not supported by application which is used to view the page. On another hand i have to post data if selected value is changed because the page going to be changed according to what user have selected. Unfortunately this can not be done using more than one page. – Roman Kupin Jan 13 '11 at 15:26
  • 1
    @Roman Kupin: Then there is a gap between your requirements and the capabilities of the user interface. It's simply not possible to do exactly what you want, so you have to figure out what you can change in the requirements. – Guffa Jan 13 '11 at 16:06
3

No, there is no auto-submit attribute for such things -- however, there is a way around it:

CSS:

#jsOn .Submit {
   display: none;
}

HTML:

<form id="my_form" action="">
<select id="justanumber" name="justanumber">
    <option value="1" selected="selected">1</option>
    <option value="2"></option>
</select>
<input type="submit" value="Go!" class="Submit" />
</form>

JavaScript:

var visible_root = document.getElementsByTagName("body");
while (visible_root.length < 1) {
    continue;
}
visible_root = visible_root[0];
visible_root.id = "jsOn";
document.getElementById("justanumber").onchange = function() {
    document.getElementById("my_form").submit();
};

When people without JavaScript arrive at your site they will see a submit button. When people with JavaScript turned on arrive at your site the submit button will be hidden and an onchange event will be added to the select element. (Alternately you could add an event listener, if you have a JavaScript library that normalizes all of the events for you.)

Sean Vieira
  • 155,703
  • 32
  • 311
  • 293
1

I don't believe this is possible without js. An obvious approach would be to set a submit button as the option's value (eg, <option><input type="submit"></option>). Unfortunately browsers will bark and moan, appending the input element after the select element. If the select determines the app flow, consider using another another UI element (eg, buttons, links, etc.).

John Himmelman
  • 21,504
  • 22
  • 65
  • 80
  • Yes it's not supported, you can't put html elements inside option. However i thought there could be something which can help to do a post. Like . But still can not figure out how to do this with select element. – Roman Kupin Jan 13 '11 at 15:35
  • @Roman: what broswer/platform are your building for? You could convert the – John Himmelman Jan 14 '11 at 02:58
  • This page supposed to be viewed by sciter (http://www.terrainformatica.com). Could you please explain in more details replacement options by submits? – Roman Kupin Jan 14 '11 at 15:00
1

Here is the answer. Unfortunately, It's not possible.

Roman Kupin
  • 232
  • 1
  • 4
  • 12
0
<form action="aaa.php" method="post" name="autosubmit_select">
<select name="justanumber" onChange="document.autosubmit_select.submit();">
    <option value="1" selected="selected">1</option>
    <option value="2"></option>
</select>
</form>
  • 1
    do add some description that,what this code will do,and what are andvantages to use this. – Hamad Nov 23 '13 at 09:17
0

agreed you must use javascript for this

please see this post How to submit form on change of dropdown list?

if your worried about users not having javascript enabled then i would suggest along with the given example in the post in the link you do this

<noscript>This form requires that you have javascript enabled to work properly please enable javascript in your browser.</noscript>

or something along those lines

other than that it is not possible to do this (currently) without the use of javascript

Community
  • 1
  • 1
Belldandu
  • 2,176
  • 1
  • 15
  • 16
0

use a submit_button to submit while JS not enabled. If JS enabled hide the button using JavaScript. Amazon did so.!

http://www.amazon.in/s/ref=nb_sb_ss_i_1_5?url=search-alias%3Delectronics&field-keywords=sd+card&sprefix=sd+ca%2Celectronics%2C401&crid=1M4KMJEGDLTEL

disable JS and see the sortby section top right corner.

Lenin J
  • 15
  • 5