从所选表单选项更改变量值(Javascript)

时间:2016-01-12 15:05:29

标签: javascript select option

我该怎么做 - 如果选项值=" 1"建筑师="比尔",var bigBoss =" Steve",var engineer =" Mike&#34 ;; if option value = 2,architect =" Marie",var bigBoss =" Ted",var engineer =" Boris"。在形式之后我有3个变量bigBoss,架构师和工程师=" 1"," 2"," 3"。我想改写它,我不能改写。它不会改写。 bigBoss只想成为" 1"

<form> 
<select name = "organizations" id="organizations" style="text-transform: uppercase; width: 312px;"> 
<option> «organization1»</option> 
<option> «organization2»</option> 
<option> «organization3»</option> 
</select> 
</form> 

<script> 

function getOrganizationName () { 
var x = document.getElementById("organizations"); 
var y = x.options[x.selectedIndex].text; 

document.getElementById("organizationName").innerHTML = y; 

getAttr(); 

}

</script> 

<script> 

function getAttr() { 

var bigBoss = "1" ; 
var architect = "2";
var engineer = "3";

}

1 个答案:

答案 0 :(得分:0)

试试这个!

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <script>
    function onOrganizationSelectionChange(selectInput) {
      console.log(selectInput.value);
    }
  </script>
</head>
<body>
<form> 
<select onchange="javascript:onOrganizationSelectionChange(this)" name = "organizations" id="organizations" style="text-transform: uppercase; width: 312px;"> 
<option value="Bob"> «organization1»</option> 
<option value="Max"> «organization2»</option> 
<option value="Ted"> «organization3»</option> 
</select> 
</form>
</body>
</html>