jeudi 14 mars 2019

Output Array Values as single comma separated line in URL

I have tried, but I still get the wrong output. I get this URL output:

php?SKU%5B%5D=B117&SKU%5B%5D=264B&SKU%5B%5D=KVS1

when I need this:

.php?SKU=B117,264B,KVS1

It appears correctly in the alert box, but not the URL. Any help would be greatly appreciated.

<form name=form1  onsubmit="chkcontrol()" method=get>
<div><input type=checkbox name=SKU[] value=B117>Add to Compare</div>
<div><input type=checkbox name=SKU[] value=264B>Add to Compare</div>
<div><input type=checkbox name=SKU[] value=KVS1>Add to Compare</div>
<div><input type=checkbox name=SKU[] value=1664>Add to Compare</div>
<div><input type=checkbox name=SKU[] value=PA03>Add to Compare</div>
<input type="submit" value="Compare" class="fsSubmitButton" />
</form>

 function chkcontrol() {
 var checkboxes = document.getElementsByName('SKU[]');
var mpn = "";
var total=0;
for (var i=0, n=checkboxes.length;i<n;i++) 
{
if (checkboxes[i].checked) 
{
    mpn += ","+checkboxes[i].value;
    total =total +1;
}
}
if (total < 2 || total > 4) {
alert("Please select 2 - 4 models to Compare") 
return false;
 } 
 if (mpn) mpn = mpn.substring(1);
 alert("SKU=" + mpn)
 alert("View your Compare Table below")
 }      `




Aucun commentaire:

Enregistrer un commentaire