SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
-
Aug 5, 2013, 08:08 #1
- Join Date
- Jun 2004
- Location
- Texas, USA
- Posts
- 118
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Parsing returned values from multiple checkboxes in JScript
When multiple checkboxes are checked, they are returned in the form of a comma delimited string, right? So you'd think it would be easy to do Request.Form('checkboxes').Item.split(",") and then iterate through the array to see which boxes were checked, right? Except I get an ASP error that the form object does not support that method. So, how do I parse that returned string to get the checked values?
Here's the HTML:
Code:<p> <label for="meat">Meat</label> <span class="err" id="errMeat">Please select one.</span><br /> <input type="checkbox" id="meat_turkey" name="meat" value="turkey" /> Turkey<br /> <input type="checkbox" id="meat_ham" name="meat" value="ham" /> Ham<br /> <input type="checkbox" id="meat_roastbeef" name="meat" value="beef" /> Roast beef<br /> <input type="checkbox" id="meat_double" name="meat" value="doublemeat" /> Double meat </p>
Code:function valid8(myArray,frmVal) { //myArray = allowed values, frmVal = returned values var ln = myArray.length; var arrFrmVal = Array(frmVal.split(",")); // Error thrown here; "Object doesn't support this property or method" for (i = 0;i < ln;i++) { for (j = 0; j < arrFrmVal.length; j++) { if (arrFrmVal[j] == (myArray[i])) { strColNames = strColNames + myArray[i] + ","; strColVals = strColVals + "'Y',"; matched = true; } } } if (matched == false) { finalMsg = finalMsg + "<br />Error: found an incomplete field"; } Response.Write("valid8 = " + strColNames + ", " + strColVals + "<br />"); }
-
Aug 7, 2013, 13:28 #2
- Join Date
- Aug 2011
- Location
- OH, USA
- Posts
- 72
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
in asp page request("meat") will be equal to "" if no any chaeckboxes checked, or single value in checked only one checkbox, so if you trying to split(",") single value like "turkey" or "" you will get error and this is what happence
-
Aug 11, 2013, 14:30 #3
- Join Date
- Oct 2002
- Location
- Scotland
- Posts
- 3,631
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
The Split method creates an array on its own - you don't need to use the Array call. That'll be why you get the error thrown.
Bookmarks