Click to See Complete Forum and Search --> : Select List


fulfill
10-31-2003, 08:41 AM
Hi,

I need help with this javascript. What I’m trying to achieve is if you 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 be 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="JavaScript"><!--
function clicked(form) {

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

</head>

<body>

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

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

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

</body>

</html>
</body>
</html>

Khalid Ali
10-31-2003, 09:01 AM
The lin below will show you the main part of the functionality,It should not be too hard from there to see if the field is empty or not and go to the next available field.
http://www.webapplikations.com/pages/html_js/forms/DropDownShowSelectionInTextField.html

fulfill
10-31-2003, 09:12 AM
Thank you for you reply but that's not what I wanted I have that code ...I want list items. for example I have 10 text boxs and they will fill in all 10 boxs from List.

Khalid Ali
10-31-2003, 01:40 PM
Originally posted by fulfill
Thank you for you reply but that's not what I wanted I have that code ...I want list items. fo

Solution above brings you to more then half way,you only have to put a condition that if a field is already filled and then go to next one.....Its not that hard..try it.