Java Script Help onSelection change input fields

A1WEBSITEPRO QuestionsCategory: JavaScriptJava Script Help onSelection change input fields
John Frank asked 1 month ago

I’m having an issue with my code. Can you tell me why it is not working?
My HTML

<form name="form1" method="post" action="">
<select name="users" onChange='Choice();'><option> </option>
<?php
foreach ($users as $key=>$value) {
echo '<option value="'.$key.'">'.$value['User']['username'].'</option>';
}
?>
</select>
<p><input type="text" id="ids" name="id" ></p>
<p><input type="text" id="ful" name="full_name" ></p>
</form>

Javascript

var ids = new Array();
var use = new Array();
var ful = new Array();
$value) {
echo "ids[" . $key . "] = '" . $value['User']['id'] . "';\n";
echo "use[" . $key . "] = '" . $value['User']['username'] . "';\n";
echo "ful[" . $key . "] = '" . $value['User']['full_name'] . "';\n";
}
?>

function Choice() {
x = document.getElementById(“users”);
x.value = y.options[y.selectedIndex].text;
document.getElementById(“ids”) = ids[y.selectedIndex];
document.getElementById(“use”) = use[y.selectedIndex];
document.getElementById(“ful”) = ful[y.selectedIndex];
}

}

Any help would be appreciated

Java Script Help onSelection change input fields was last modified: February 18th, 2017 by John Frank

1 Answers
Best Answer
Maximus Mccullough Staff answered 1 month ago

you can do it like this.

<form name="form1" method="post" action="">
<select id="selectUsers" name="users" onChange="Choice();">
<option></option>
<option value="1">bsmith</option>
<option value="2">lsmith</option>
<option value="3">asmith</option>
</select>
<p>ids <input type="text" id="ids" name="id" ></p>
<p>use <input type="text" id="use" name="username" ></p>
<div id="ddd">
<p>ful <input type="text" id="ful" name="full_name" ></p>
</div>
</form>
<script>var ids = new Array();
var use = new Array();
var ful = new Array();
ids[0] = "";
use[0] = "";
ful[0] = "";

ids[1] = 6;
use[1] = "bsmith";
ful[1] = "Buddy Smith";

ids[2] = 2;
use[2] = "lsmith";
ful[2] = "Libbie Smith";

ids[3] = 4;
use[3] = "asmith";
ful[3] = "Andy Smith";
function Choice() {
y = document.getElementById("selectUsers");
document.getElementById("ids").value = ids[y.selectedIndex];
document.getElementById("use").value = use[y.selectedIndex];
document.getElementById("ful").value = ful[y.selectedIndex];
}
</script>
Answer for Java Script Help onSelection change input fields was last modified: February 18th, 2017 by Maximus Mccullough