...

View Full Version : Remove entry from array and repost form



Schteeve
03-16-2009, 02:06 PM
Hi all,

I am trying to accomplish a fairly basic task with javascript > my lack of Js knowledge has meant i have hit something of a roadblock.

I need the a function to take an array from a form, remove the parsed variable from it and repost the form with the new array.

This is what I have so far...


<script language="javascript">

function remove(SID) {

var speakers = document.form_name.elements["SID[]"];
var new_speakers = array();

for(i=0;i<speakers.length;i++)
{
if( speakers[i].value !== SID) {

new_speakers[] = speakers[i].value;

}
}

document.form_name.SID.value=(new_speakers);

document.form_name.submit();

}

</script>

Please let me know if this is possible and if I'm on the right path.

Any help is very much appreciated!!

Thanks

Steve

Philip M
03-16-2009, 02:34 PM
var new_speakers = new Array();

new_speakers[i] = speakers[i].value;

document.form_name.SID.value = new_speakers; // no brackets necessary

Schteeve
03-16-2009, 04:59 PM
Thanks Phillip.

All sorted now!

Thanks for your help!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum