PHP - How to send a selection menu without a button

Is it possible to automatically submit the selection menu when the selection changes without using the button to submit the form. I have four of them on my page, and using the button for each uses too much space. In the "Select" menu, I mean:

<select name="something" class="something" title="something something">
  <option selected="selected">Option One</option>
  <option >Option Two</option>
</select>

I would also like to add a popup confirmation for the on change event. The following is what I use for buttons, but it does not work for the select menu.

onclick="return confirm('do you haz teh codz?');"

Any reference to articles or examples is appreciated.

thank

+3
source share
4 answers

This is a more appropriate javascript tag, since it is the javascript that you will use for this.

"onchange" . "" node.

<select name="something" class="something" title="something something" onchange="form.submit()">
<option selected="selected">Option One</option>
  <option >Option Two</option>
</select>
+6

JavaScript, PHP. PHP , ; , .

JavaScript :

  • <select> (onchange).
  • <select> .
  • ( window.location) , .

:. , , <select>, mwotton - , , . (, JavaScript HTML, .)

- :

document.getElementById('my-select').onchange = function(){
    return confirm('do you haz teh codz?');
});

( JavaScript HTML. <select> , id="my-select", JavaScript. JavaScript, ​​ jQuery, JavaScript.)

+2

onchange , form.submit();

0

, / - . <form id="selectform"> <select id="selectelement">,

window.onload=function() {
  document.getElementById('selectelement').change = function() {
    if(confirm('do you haz teh codz?'))
      document.getElementById('selectform').submit();
    else
      return false;
    return true;
  }
}

Returning false / true determines whether to return the selection back to the original option.

Here's the test: http://jsfiddle.net/yrqcj/2/

0
source

Source: https://habr.com/ru/post/1771620/


All Articles