PDA

Click to See Complete Forum and Search --> : Problems with selectbox & Jscript


Bombdrop
Apr 30th, 2004, 05:14 AM
Hi all I'm not much cop at JavaScript ( thought i do thinlk it's pretty cool) now how can i display the value of an item the code bellow sort of works


<SCRIPT LANGUAGE="JavaScript">
<!--

function submitform_List() {

alert("TEST!!!");
document.choiceForm.MyAccount.length++;
alert(document.choiceForm.MyAccount.length);
alert(document.choiceForm.MyAccount[0].text);

document.choiceForm.MyAccount[1].text="BombDrop";

//I can not display the value i have added to the new option???
document.choiceForm.MyAccount[1].value="123";
alert(document.choiceForm.MyAccount.value);


//document.choiceForm.submit();
}
</script>


Any help would be great
:wave: :thumb: :wave:

CornedBee
Apr 30th, 2004, 05:44 AM
Just incrementing the length doesn't add an actual item!
<script type="text/javascript">
function submitform_list() {
var form = document.getElementById("choiceForm");
var select = form.elements["MyAccount"];
var option = document.createElement("option");
option.text = "BombDrop";
option.value = "123";
select.appendChild(option);
// Now there's a real new option there.
alert(select.options[select.options.length-1].value);
}
</script>

http://www.quirksmode.org/
contains a lot of resources on proper JavaScript.