S
S
Sergey2018-02-13 15:44:49
JavaScript
Sergey, 2018-02-13 15:44:49

How to pass value from select to action?

I take the data from the select, but I can't insert it into the action of the form!

<form method="post" id="sys" action="link.php">
  <p><select id="selec" name="sys" onchange="change()">
  <option value=''>Choose</option>
    <option value="1" >1</option>
    <option value="2" >2</option>
    </select></p>
</form>

var select, value;

function change() {
    select = document.getElementById("selec"); 
    value = select.options[select.selectedIndex].value; 
    document.sys.action = "/AAA";
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stimulate, 2018-02-13
@alekskondr

https://jsfiddle.net/d7006ykn/1/

T
twobomb, 2018-02-13
@twobomb

<script>
window.onload = function(){
  document.all.selec.onchange = function(){
  document.all.sys.setAttribute("action",this.value);
  }
}
</script>
<form method="post" id="sys" action="link.php">
  <p><select id="selec" >
  <option value=''>Choose</option>
    <option value="1" >1</option>
    <option value="2" >2</option>
    </select></p>
</form>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question