/    Sign up×
Community /Pin to ProfileBookmark

Passing Option Text

I want to pass the text (<option>[B]THIS TEXT IS TO BE PASSED[/B]) for the option to another field.

I also need it to work with my existing code:

HTML file-

[CODE]<html><head>
<script language=javascript src=”chose.js”></script></head>
<body>
<form id=selectFRM>
<table>
<tr><td>
<table>
<tr>
<td>Selection #1</td></tr>

<tr>
<td><select id=sel1 name=sel1 STYLE=width:250 onChange=”populateNxt(this, selectFRM.sel2, arrItems1, arrItemsGrp1)”><option selected>Start Here
<option value=1>Selection 1 Option 1
<option value=2>Selection 1 Option 2
<option value=3>Selection 1 Option 3</select></td></tr>

<tr>
<td>Selection #2</td></tr>

<tr>
<td><select id=sel2 name=sel2 STYLE=width:250 onChange=”populateNxt(this, selectFRM.sel3, arrItems2, arrItemsGrp2)”></select></td></tr>

<tr>
<td>Selection #3</td></tr>

<tr>
<td><select id=sel3 name=sel3 STYLE=width:250></select></td></tr>
</table></td>

<td>
<table>
<tr>
<td>&nbsp;</td></tr>

<tr>
<td><input type=text readonly id=txt1></td></tr>

<tr>
<td>&nbsp;</td></tr>

<tr>
<td><input type=text readonly id=txt2></td></tr>

<tr>
<td>&nbsp;</td></tr>

<tr>
<td><input type=text readonly id=txt3></td></tr>
</table></td></tr>
</table>
</form>
</body></html>[/CODE]

and the [B]chose.js[/B] file-

[CODE]var arrItems1 = new Array();
var arrItemsGrp1 = new Array();
arrItems1[1] = “Selection 2 Option 1 from (Option 1)”;
arrItemsGrp1[1] = 1;
arrItems1[2] = “Selection 2 Option 2 from (Option 1)”;
arrItemsGrp1[2] = 1;
arrItems1[3] = “Selection 2 Option 2 from (Option 2)”;
arrItemsGrp1[3] = 2;
arrItems1[4] = “Selection 2 Option 2 from (Option 2)”;
arrItemsGrp1[4] = 2;
arrItems1[5] = “Selection 2 Option 1 from (Option 3)”;
arrItemsGrp1[5] = 3;
arrItems1[6] = “Selection 2 Option 2 from (Option 3)”;
arrItemsGrp1[6] = 3;

var arrItems2 = new Array();
var arrItemsGrp2 = new Array();
arrItems2[1] = “Selection 3 Option 1 from (Options 1,1)”;
arrItemsGrp2[1] = 1
arrItems2[2] = “Selection 3 Option 1 from (Options 1,2)”;
arrItemsGrp2[2] = 2
arrItems2[3] = “Selection 3 Option 1 from (Options 2,1)”;
arrItemsGrp2[3] = 3
arrItems2[4] = “Selection 3 Option 1 from (Options 2,2)”;
arrItemsGrp2[4] = 4
arrItems2[5] = “Selection 3 Option 1 from (Options 3,1)”;
arrItemsGrp2[5] = 5
arrItems2[6] = “Selection 3 Option 1 from (Options 3,2)”;
arrItemsGrp2[6] = 6

function populateNxt(control, controlToPopulate, ItemArray, GroupArray) {
var myEle ;
var x ;
for (var q=controlToPopulate.options.length;q>=0;q–) controlToPopulate.options[q]=null;
if (control.name == “sel1”) {
for (var q=selectFRM.sel3.options.length;q>=0;q–) selectFRM.sel3.options[q] = null;
}

myEle = document.createElement(“option”) ;
myEle.value = 0 ;
myEle.text = “Next” ;
controlToPopulate.add(myEle) ;

for ( x = 0 ; x < ItemArray.length ; x++ ) {
if ( GroupArray[x] == control.value ) {
myEle = document.createElement(“option”) ;
myEle.value = x ;
myEle.text = ItemArray[x] ;
controlToPopulate.add(myEle) ;
}
}
}[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@zamerothauthorMay 17.2005 — Answered my own question..ha!

I placed this:

[CODE]function pasteIt() {
var daInx1 = document.getElementById('sel1').selectedIndex;
var goTxt1 = document.getElementById('sel1').options[daInx1].text;
var daInx2 = document.getElementById('sel2').selectedIndex;
var goTxt2 = document.getElementById('sel2').options[daInx2].text;
var daInx3 = document.getElementById('sel3').selectedIndex;
var goTxt3 = document.getElementById('sel3').options[daInx3].text;
document.getElementById('txt1').value=goTxt1;
document.getElementById('txt2').value=goTxt2;
document.getElementById('txt3').value=goTxt3;
}[/CODE]


in the chose.js file.

and edited the HTML file by adding this:

[CODE]<td><select id=sel3 name=sel3 STYLE=width:250 [B]onChange="pasteIt[/B]()"></select></td></tr>[/CODE]

to the final select box.
×

Success!

Help @zameroth spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...