JayGuarnieri Posted November 27, 2014 Report Share Posted November 27, 2014 Can't figure out what would cause this problem. In the code below cbParamVirtual7 ,8 and 10 field values are all being passed to a new datapage as I'd expect. 9 and 11 are passing no values. I've ruled out the results datapage accepting the values as I can input the parameters manually using the preview option and get the desired result. I've gone over and over this and cannot find anything wrong. Can someone give me pointers as to a possible cause or where to go next? <SCRIPT LANGUAGE="JavaScript"> /* "fieldName" is the variable name for the listbox type form element field. */ var fieldName1 = "cbParamVirtual1"; var fieldName2 = "cbParamVirtual2"; var fieldName3 = "cbParamVirtual3"; var fieldName4 = "cbParamVirtual4"; var fieldName5 = "cbParamVirtual5"; var x1=document.getElementsByName(fieldName1); var x2=document.getElementsByName(fieldName2); var x3=document.getElementsByName(fieldName3); var x4=document.getElementsByName(fieldName4); var x5=document.getElementsByName(fieldName5); x1[0].multiple=true; x2[0].multiple=true; x3[0].multiple=true; x4[0].multiple=true; x5[0].multiple=true; </SCRIPT> <script type="text/javascript"> var fieldName1 = "cbParamVirtual1"; var fieldName2 = "cbParamVirtual2"; var fieldName3 = "cbParamVirtual3"; var fieldName4 = "cbParamVirtual4"; var fieldName5 = "cbParamVirtual5"; var x1=document.getElementsByName(fieldName1); x1[0].multiple=true; var x2=document.getElementsByName(fieldName2); x2[0].multiple=true; var x3=document.getElementsByName(fieldName3); x3[0].multiple=true; var x4=document.getElementsByName(fieldName4); x4[0].multiple=true; var x5=document.getElementsByName(fieldName5); x5[0].multiple=true; function splitAndParse() { var result1 = ""; var result2 = ""; var result3 = ""; var result4 = ""; var result5 = ""; var cleanResult1 = ""; var cleanResult2 = ""; var cleanResult3 = ""; var cleanResult4 = ""; var cleanResult5 = ""; for (var i = 0; i < x1[0].length; i++) { if (x1[0].options[i].selected) { result1 += "\""+x1[0].options[i].value+"\"" + " OR " ; }} if (x1[0].length > 4) { cleanResult1 = result1.substring(0,(result1.length-4)); } document.getElementById("cbParamVirtual7").value = cleanResult1; for (var i = 0; i < x2[0].length; i++) { if (x2[0].options[i].selected) { result2 += "\""+x2[0].options[i].value+"\"" + " OR " ; }} if (x2[0].length > 4) { cleanResult2 = result2.substring(0,(result2.length-4)); } document.getElementById("cbParamVirtual8").value = cleanResult2; for (var i = 0; i < x3[0].length; i++) { if (x3[0].options[i].selected) { result3 += "\""+x3[0].options[i].value+"\"" + " OR " ; }} if (x3[0].length > 4) { cleanResult3 = result3.substring(0,(result3.length-4)); } document.getElementById("cbParamVirtual9").value = cleanResult3; for (var i = 0; i < x4[0].length; i++) { if (x4[0].options[i].selected) { result4 += "\""+x4[0].options[i].value+"\"" + " OR " ; }} if (x4[0].length > 4) { cleanResult4 = result4.substring(0,(result4.length-4)); } document.getElementById("cbParamVirtual10").value = cleanResult4; for (var i = 0; i < x5[0].length; i++) { if (x5[0].options[i].selected) { result5 += "\""+x5[0].options[i].value+"\"" + " OR " ; }} if (x5[0].length > 4) { cleanResult5 = result5.substring(0,(result5.length-4)); } document.getElementById("cbParamVirtual11").value = cleanResult5; } document.getElementById("caspioform").onsubmit=splitAndParse; </script> Quote Link to comment Share on other sites More sharing options...
JayGuarnieri Posted November 30, 2014 Author Report Share Posted November 30, 2014 Well, 3 days of looking at this and still can't figure it out. cbParamVirtual3 and 5 have the correct values but something happens during the splitAndParse function and they never make it to cbParamVirtual9 and 11. Stumped! Quote Link to comment Share on other sites More sharing options...
Jan Posted December 1, 2014 Report Share Posted December 1, 2014 Hello Bobsgoodeye, It seems the code is correct. Maybe, the reason is in something else. Are all fields (cbParamVirtual1-cbParamVirtual5) the same Form element? Could you provide the URL? Quote Link to comment Share on other sites More sharing options...
JayGuarnieri Posted December 1, 2014 Author Report Share Posted December 1, 2014 Hey Jan, Yes, they are all on the same form. Just one form feeding a results page. Do you mean the site url or the app? Thanks Jay Quote Link to comment Share on other sites More sharing options...
Jan Posted December 1, 2014 Report Share Posted December 1, 2014 Hi Jay, I mean, are all they "TextField"s? Or is cbParamVirtual9 a dropdown? Some FormElements have specific values. If you provide the URL of the DataPage, maybe, I will be able to find the reason of the issue. Quote Link to comment Share on other sites More sharing options...
JayGuarnieri Posted December 1, 2014 Author Report Share Posted December 1, 2014 Right, I'm with you now. http://eu1.caspio.com/dp.asp?AppKey=d55b3000ebf211919bc94d4ca485 All listboxes. cbParamVirtual1 - 5 using only text fields. cbParamVirtual6 (which doesn't have to be split) is a number field. Quote Link to comment Share on other sites More sharing options...
Jan Posted December 3, 2014 Report Share Posted December 3, 2014 Hi Jay, I have created the copy of you page (with my test data) and used your code. If I understand correctly, the problem appears, if a user selects "Any" field - than empty value is added to the Virtual field. You can enter the correct value to the "Any" item, it will be like: a1" OR "a2" OR "a3" OR "a4" OR "a5 Please do not add quotes before and after the text, because the quotes are added with the JavsScript code. To see, what data is inserted to the corresponding fields, you can make your VirtualFields 7-11 as TextFields and add the line "return false" to the code: for (var i = 0; i < x5[0].length; i++) { if (x5[0].options[i].selected) { result5 += "\""+x5[0].options[i].value+"\"" + " OR " ; }} if (x5[0].length > 4) { cleanResult5 = result5.substring(0,(result5.length-4)); } document.getElementById("cbParamVirtual11").value = cleanResult5; return false; } document.getElementById("caspioform").onsubmit=splitAndParse; </script> then no data will be inserted in the table and you can see values that are inserted in the corresponding fields. Quote Link to comment Share on other sites More sharing options...
JayGuarnieri Posted December 3, 2014 Author Report Share Posted December 3, 2014 Hi Jan, thanks for coming back to me. Just to clarify when you say "Any" field, do you mean when the user makes any selection at all or when they make the selction "Any". For the record, no matter what selection (or multiple selections) they make in the list box, an empty value is passed (or nothing is passed). Using "return false;" I confirmed that the fields Virtual9 and 11 had no value (not even "") but I'm not sure what you mean by You can enter the correct value to the "Any" item, it will be like: a1" OR "a2" OR "a3" OR "a4" OR "a5 Quote Link to comment Share on other sites More sharing options...
Jan Posted December 3, 2014 Report Share Posted December 3, 2014 Hi Jay, Using "return false;" you only stop the submission and can see what values are inserted in Virtual Fields 7-11. When I tried with my DataPages, I have checked that all values are passed correctly to Virtual Fields. If the values are passed correctly on your DataPage too, then the reason of the issue may be on the next DataPage. I mean, "-- Any --" items that are displayed at the top of Listboxes and they are selected by default. If you edit a ListBox, you can see two fields for every item: "Display" and "Value". If I understand correctly, now the "-- Any --" text is entered to the "Display" and nothing is entered to the "Value". If you want to pass all values, you can enter all these values to this field, for example, for "Brakes" listbox it will beRim" OR "Rim (Disc ready)" OR "Disc only Quote Link to comment Share on other sites More sharing options...
JayGuarnieri Posted December 3, 2014 Author Report Share Posted December 3, 2014 Hi Jan, So it worked correctly when you ran it? return false is really handy for troubleshooting. Thanks. I think we're talking slightly at crossed purposes though. It's not just when I select "-- Any --" in those two fields. No matter what selection is made no value appears to be attributed to Virtual9 and 11. Quote Link to comment Share on other sites More sharing options...
Jan Posted December 3, 2014 Report Share Posted December 3, 2014 Hi Jay, It worked with my listboxes and values. Can I try select different itmes on your DataPage now to see which values are passed? Quote Link to comment Share on other sites More sharing options...
JayGuarnieri Posted December 3, 2014 Author Report Share Posted December 3, 2014 Hi Jan, I won't be working on it until tomorrow so do your worst Quote Link to comment Share on other sites More sharing options...
Jan Posted December 5, 2014 Report Share Posted December 5, 2014 Hi Jay, I have found the reason. The line if (x5[0].length > 4) { cleanResult5 = result5.substring(0,(result5.length-4)); } Defines that value will be passed only if the Listbox contains 5 and more items. My listboxes contained 5 and more items and the Script worked. I changed them to 4 items - and your issue reproduced. You can change all lines to if (x5[0].length > 0) { cleanResult5 = result5.substring(0,(result5.length-4)); } Change "4" to "0" after "(x5[0].length >" I have tested with this new value. It works on my DataPage. I hope, it helps. Quote Link to comment Share on other sites More sharing options...
JayGuarnieri Posted December 6, 2014 Author Report Share Posted December 6, 2014 Hi Jan, Many many thanks. All working. I'm really annoyed with myself as this was one of the very first things I looked at. I can't remember why I decided this wasn't the problem. Thanks again. Quote Link to comment Share on other sites More sharing options...
Jan Posted December 8, 2014 Report Share Posted December 8, 2014 Hi Jay, You are very welcome! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.