I want to add items to a list and then submit these items via POST in a
form. Below is my code and it adds the items fine but they are not selected
when I submit the form how can I have them all selected when I submit the
form?
Any help would be most appreciated!!!
Thanks in advance!!
<script type="text/javascript">
function addOption(selec tObject,optionT ext,optionValue ) {
var optionObject = new Option(optionTe xt,optionValue)
var optionRank = selectObject.op tions.length
selectObject.op tions[optionRank]=optionObject
}
function deleteOption(se lectObject,opti onRank) {
if (selectObject.o ptions.length!= 0) {
selectObject.op tions[optionRank]=null }
}
function testAdd() {
var formObject = document.testFo rm
if (formObject.opt ionText.value!= "" && formObject.opti onValue.value!= "")
{
addOption(formO bject.fruitList ,formObject.opt ionText.value,f ormObject.optio nValue.value)
} else {
alert("Fill form and click Add")
}
}
function testDelete() {
var formObject = document.testFo rm
if (formObject.fru itList.selected Index!=-1) {
deleteOption(fo rmObject.fruitL ist,formObject. fruitList.selec tedIndex)
} else {
alert("Select an option and click Delete")
}
}
</script>
<!---- ***** Start of the Form ***** ---->
<form action="testa.c fm" method="post" name="testForm" >
<input name="JOHN" type="text" value="123">
<p>
<select name="fruitList " size="10" multiple>
<option value="TEST" selected>TEST</option>
</select>
<br/>
Fill form and click Add :<br/>
Option Text : <input type="text" name="optionTex t"/>
Option Value : <input type="text" name="optionVal ue"/>
<input type="button" value="Add" onclick="testAd d()"/><br/>
Select an option and click Delete : <input type="button" value="Delete"
onclick="testDe lete()"/>
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
form. Below is my code and it adds the items fine but they are not selected
when I submit the form how can I have them all selected when I submit the
form?
Any help would be most appreciated!!!
Thanks in advance!!
<script type="text/javascript">
function addOption(selec tObject,optionT ext,optionValue ) {
var optionObject = new Option(optionTe xt,optionValue)
var optionRank = selectObject.op tions.length
selectObject.op tions[optionRank]=optionObject
}
function deleteOption(se lectObject,opti onRank) {
if (selectObject.o ptions.length!= 0) {
selectObject.op tions[optionRank]=null }
}
function testAdd() {
var formObject = document.testFo rm
if (formObject.opt ionText.value!= "" && formObject.opti onValue.value!= "")
{
addOption(formO bject.fruitList ,formObject.opt ionText.value,f ormObject.optio nValue.value)
} else {
alert("Fill form and click Add")
}
}
function testDelete() {
var formObject = document.testFo rm
if (formObject.fru itList.selected Index!=-1) {
deleteOption(fo rmObject.fruitL ist,formObject. fruitList.selec tedIndex)
} else {
alert("Select an option and click Delete")
}
}
</script>
<!---- ***** Start of the Form ***** ---->
<form action="testa.c fm" method="post" name="testForm" >
<input name="JOHN" type="text" value="123">
<p>
<select name="fruitList " size="10" multiple>
<option value="TEST" selected>TEST</option>
</select>
<br/>
Fill form and click Add :<br/>
Option Text : <input type="text" name="optionTex t"/>
Option Value : <input type="text" name="optionVal ue"/>
<input type="button" value="Add" onclick="testAd d()"/><br/>
Select an option and click Delete : <input type="button" value="Delete"
onclick="testDe lete()"/>
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
Comment