Javascript "implode" alternative to PHP "implode"

<html>
<head>
<title>Form</title>
</head>

<body>
<form action="form.php" method="get">
<div class=""><input name="field" value="1" type="checkbox"> Option One </div>
<div class=""><input name="field" value="2" type="checkbox"> Option Two </div>
<div class=""><input name="field" value="3" type="checkbox"> Option Three </div>
<input class="fsubmit" src="images/buttons/find.gif" value="Show Threads" type="submit">
</form>
</body>
</html>

Here is the equation. The form above appends field values to the URL that looks like:

www.mysite.com/form.php?field=1&field=2&field=3

What I’m trying to achieve is something like:

www.mysite.com/form.php?field=1,2,3

Would someone suggest a way to do that? Not sure if that’s got to be a javascript way of doing it, just guessing.

Thanks.

In JavaScript Array values can be imploded together into a single string with the ‘join’ method of the Array Object


<script type="text/javascript">
    var testArray = new Array();
    testArray[0] = 'first';
    testArray[1] = 'second';
    testArray[2] = 'third';
    
    alert(testArray.join(',')); // returns the string  'first,second,third'
    
</script>

For more details, check this reference.

Thanks, Kailash.