Write onclick

<script type="text/javascript">
function setOptions(chosen) {
var izbor = document.form3.celik;
izbor.options.length = 0;
if (chosen == " ") {
  izbor.options[izbor.options.length] = new Option('choose',' ');
if (chosen == "okc") {
  izbor.options[izbor.options.length] = new Option('C0270','C0270');
  izbor.options[izbor.options.length] = new Option('C0370','C0370');
if (chosen == "pc") {
  izbor.options[izbor.options.length] = new Option('C1330','C1330');
  izbor.options[izbor.options.length] = new Option('C1530','C1530');

if (chosen == "cc") {
  izbor.options[izbor.options.length] = new Option('C1120','C1120');
  izbor.options[izbor.options.length] = new Option('C1220','C1220');



<select name="vrsta" size="1"
          <option value=" " selected="selected"> </option>
          <option value="okc">Opsti konstrukcijski celici</option>
          <option value="pc">Poboljsani celici</option>
          <option value="cc">Cementirani celici</option>

<select name="celik" size="1">
        <option value=" " selected="selected">Izabrati prvo vrstu</option>

<input type="button" value=" ok "  onclick="form3.ans15.value(document.form3.vrsta.options[document.form3.vrsta.selectedIndex].value);" />

<input type="type" "number" value="" name="ans15" size="9" />
<input type="type" "number" value="" name="ans14" size="9" />

I dont know how to write something in ans15 and ans14 onclick of button
Example…if user selects new Option(‘C0270’,‘C0270’) and clicks on button it should write something in ans15 and ans14
I tried
<input type=“button” value=" ok " onclick=“form3.ans15.value(document.form3.vrsta.options[document.form3.vrsta.selectedIndex].value);” />

but it is not good…

You can add options to any of the options lists
<option value=“4”>Additional option 4</option>
<option value=“5”>Additional option 5</option>

You will need to add corresponding entries in the data array
eg: for okc.length=4 and 5:
okc[okc.length]={text1:“anything”,value2:“something else” };
okc[okc.length]={text1:“another”,value2:“something else again” };

Keep in mind that okc.length is just another way of creating the array index number. In the first array entry okc.length=0, in the next it equals 1 and so on until the data has all been entered.

Whatever you enter into the data array for text1 and value2 will be transferred to the two boxes if you select that option. You can add a 3rd box (ans13), but you will need to add an additional data field into the data array to paste into the new box.
okc[okc.length]={text1:“C0370”,value2:“C0370V”,newItem1:“hello” };
Now when you write text1 and value2 you can also write newItem1 to the new box ans13. If you go this way, you will need to add the new field to all of the data arrays to make it work.


Is there a possibility to add another value…another answer…like

and…can it write other values to boxes?
okc[okc.length]={text1:“C0270”,value2:“C0270V” }; not C0270 and C0270V but different values…

these options in first list

<option value=“1”>Opsti konstrukcijski celici</option>
<option value=“2”>Poboljsani celici</option>
<option value=“3”>Cementirani celici</option>

these in second

okc[okc.length]={text1:“Select here”,value2:“” };
okc[okc.length]={text1:“C0270”,value2:“C0270V” };
okc[okc.length]={text1:“C0370”,value2:“C0370V” };

but in box to write something else

if selected C0270 to write hello

I have modified your script a little but you will get the idea. Not sure what you intended with the boxes, but I filled them with the text and value components of your selection in the 2nd select box. Hope this helps.



<script type=“text/javascript”>
// option arrays
var okc=new Array(); //global
okc[okc.length]={text1:“Select here”,value2:“” };
okc[okc.length]={text1:“C0270”,value2:“C0270V” };
okc[okc.length]={text1:“C0370”,value2:“C0370V” };

var pc=new Array(); //global
pc[pc.length]={text1:“Select here”,value2:“” };
pc[pc.length]={text1:“C1330”,value2:“C1330V” };
pc[pc.length]={text1:“C1530”,value2:“C1530V” };

var cc=new Array(); //global
cc[cc.length]={text1:“Select here”,value2:“” };
cc[cc.length]={text1:“C1120”,value2:“C1120V” };
cc[cc.length]={text1:“C1220”,value2:“C1220” };
// -------------------
// put the three arrays into another array
var allArray=[null,okc, pc, cc];
// ======= end of array setup ==============
var celikObj=null; // global
// initialise page
function init()
{ // get object ref to target select box
// ========= end init =====================
// get selection and fill options list
function getSelected(obj)
{ // invalid selection
{ celikObj.disabled=true;
// ------------
// valid selection, so continue
// put object items list into select box after clearing
for(var i=celikObj.options.length-1;i>-1;i–){ celikObj.options[i]=null; }
// fill options list
arrayIndx=obj.options[obj.selectedIndex].value; // ref to a array above
var i, thisItem=0; // initialise variables
// build options list
{ thisItem=allArray[arrayIndx][i]; // arrayIndx=inner array, i=elements of inner array
celikObj.options[i]=new Option(thisItem.text1,thisItem.value2 ,false,false);
// =============== end getSelected ==========
function writeBox(obj)
{ // invalid selection
if(obj.selectedIndex==0){ return; }
// ------------
// =============== end writeBox ==============
<style type=“text/css”>
#form1 { margin-top:100px; }

<body onload=“init()”>

<p><select name=“vrsta” size=“1” onchange=“getSelected(this)”>
<option value=“0” selected>Select an option</option>
<option value=“1”>Opsti konstrukcijski celici</option>
<option value=“2”>Poboljsani celici</option>
<option value=“3”>Cementirani celici</option>
</select> </p>
<p><select name=“celik” id=“celik” size=“1” onchange=“writeBox(this)”>
<option value=" " selected>Select an option</option>
</select> </p>
<form name=“form1” id=“form1” action>
<p><input type=“text” name=“ans15” size=“9”>
<input type=“text” name=“ans14” size=“9”> </p>



ok…i tried something like that

okc[okc.length]={text1:“C0270”,value2:“C0270V” ,value3:“hello”};

What should be in bolded place…can i do it with value1, value2 etc?

celikObj.options[i]=new Option(thisItem.text1,thisItem.value2 ,false,false);

should i put that new options here like:
celikObj.options[i]=new Option(thisItem.text1,thisItem.value2 ,thisItem.value3,false,false,false);

and i added
in function getSelected(obj)