Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select List

Status
Not open for further replies.

FulFill

IS-IT--Management
Dec 5, 2001
13
US
Hi,

I need help with this javascript. What I’m trying to achieve is if user selects any item from list it should populate in text box if text box is already filled then it should not over ride the first one but it should populate in next available text box.

Now code is working only if the user selects list of items with CTRL and it will populate in all fields, but that’s not what I wanted they should have two options user can select one at a time all at a time.

Conditions if user already selected item from the list and if by accidentally clicks on the same item it should give a warning mesg “not allowed” unless user delete’s and re-select
and the user have choice to remove any items and select diff one at any time.

Can you guys help with this I really appreciate for your help guys.


<script language=&quot;JavaScript&quot;><!--
function clicked(form) {

for (var i=0, j=i; i < form.selectName.options.length; i++) {
if (form.elements['currentText' + j].value = &quot;&quot;){
j = j++;
}
if (form.selectName.options.selected) {
form.elements['currentText' + j].value = form.selectName.options.text;
form.elements['currentValue' + j].value = form.selectName.options.value;
j++;
}
}
}
//--></script>

</head>

<body>

<form name=&quot;formName1&quot; onSubmit=&quot;return false;&quot; >
<select name=&quot;selectName&quot; multiple onClick=&quot;clicked(this.form);return false;&quot;>
<option value=&quot;option 0&quot;>entry 0
<option value=&quot;option 1&quot;>entry 1
<option value=&quot;option 2&quot;>entry 2
<option value=&quot;option 3&quot;>entry 3
<option value=&quot;option 4&quot;>entry 4
<option value=&quot;option 5&quot;>entry 5
</select>
<input type=&quot;submit&quot; value=&quot;Enter&quot; onClick=&quot;clicked(this.form);return false;&quot;>
<input type=&quot;reset&quot; value=&quot;clear&quot;>

<p>
Select items from the above menu, then press enter.
The following boxes will display your choices:
</p>

<p>
<input name=&quot;currentText0&quot; type=&quot;text&quot; value=&quot;&quot;>
<input name=&quot;currentValue0&quot; type=&quot;text&quot; value=&quot;&quot;>
<br>
<input name=&quot;currentText1&quot; type=&quot;text&quot; value=&quot;&quot;>
<input name=&quot;currentValue1&quot; type=&quot;text&quot; value=&quot;&quot;>
<br>
<input name=&quot;currentText2&quot; type=&quot;text&quot; value=&quot;&quot;>
<input name=&quot;currentValue2&quot; type=&quot;text&quot; value=&quot;&quot;>
<br>
<input name=&quot;currentText3&quot; type=&quot;text&quot; value=&quot;&quot;>
<input name=&quot;currentValue3&quot; type=&quot;text&quot; value=&quot;&quot;>
<br>
<input name=&quot;currentText4&quot; type=&quot;text&quot; value=&quot;&quot;>
<input name=&quot;currentValue4&quot; type=&quot;text&quot; value=&quot;&quot;>
<br>
<input name=&quot;currentText5&quot; type=&quot;text&quot; value=&quot;&quot;>
<input name=&quot;currentValue5&quot; type=&quot;text&quot; value=&quot;&quot;>
</form>

</body>

</html>
</body>
</html>
 
Do you want the text boxes filled in the order that the options were selected? In other words, if I click on option 5 should it go into text 0?

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Yes it should go in order which ever one is clicked first it should fill in first box and so on.

For example : From List I select no 7 and First text field is emply is it should fill First one.

Thank you
 
I'm having some problems with the selecting one vs multiple... Are you positive that this is the way you want it done? Can you use a list of checkboxes by any chance?

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Try this javascript the other script had extra if statement that might be causing problem for you,

ya I want like this cz my customers will select items from items and fill the form.

here is the javascript.

<script language=&quot;JavaScript&quot;><!--
function clicked(form) {

for (var i=0, j=i; i < form.selectName.options.length; i++) {
if (form.selectName.options.selected) {
form.elements['currentText' + j].value = form.selectName.options.text;
form.elements['currentValue' + j].value = form.selectName.options.value;
j++;
}
}
}
//--></script>


Thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top