Actually, I don't think you should need to validate the count if your loop has been written correctly and the count is correct. What code do you have currently for inserting parts?
displaying previously entered multiple fields
Collapse
X
-
Originally posted by acoderActually, I don't think you should need to validate the count if your loop has been written correctly and the count is correct. What code do you have currently for inserting parts?
Here is what i have for inserting
Code:<!---Allows us to add serial information multiple times ---> <script type="text/javascript"> <!---Allows us to add multiple fields ---> function addInput(divName){ var dynamic = document.getElementById('dynamicInput'); var thevalue = document.getElementById('theValue'); var count = (document.getElementById('theValue').value -1)+ 2; thevalue.value = count; var newdiv = document.createElement('div'); var getparts = document.createElement('div'); var divIdName = 'dynamic'+count+'Input'; var partc = 'partscount'+count; newdiv.setAttribute('id',divIdName); <!--- Adds Extra fields for Model No, Product Type, and Type of Hardware Failure ---> newdiv.innerHTML = "<table class='zpExpandedTable' id='modeltable'>" + "<th class='sectiontitletick' colspan='7'>Serial Information "+ count +" </th>" + "<tr>" + "<td id='paddingformultitop'>Model No: </td>" + "</td>" + "<td>" + "<select name='modelno_" + count + "' >" + "<option value=''>Make A Selection</option>" + "<cfoutput query='models'>" + "<option value='#model#'>#model#</option>" + "</cfoutput>" + "</select>" + "</td>" + "<td>" + " Product Type:" + "</td>" + "<td>" + "<select name='producttype_" + count + "'>" + "<option value='' selected>No Choice</option>" + "<cfoutput query='getProdType'>" + "<option value='#pk_productType#'>#pk_productType#</option>" + "</cfoutput>" + "</select>" + "</td>" + "<td class='red'>" + " Type Of Hardware Failure*:" + "</td>" + "<td>" + "<select name='hardwarefailure_" + count + "'>" + "<option value='' selected>Make A Selection</option>" + "<cfoutput query='getHardwareFail'>" + "<option value='#pk_hardwareFailure#'>#pk_hardwareFailure#</option>" + "</cfoutput>" + "</select>" + "</td>" + "</tr>" + "<table>"; <!--- Adds Extra fields for Serial Number and Software/Hardware ---> newdiv.innerHTML = newdiv.innerHTML + "<table class='zpExpandedTable' id='modeltable'>" + "<tr>" + "<td id='paddingformultitop'>" + "Serial Number: " + "<input type='text' name='serialnum_" + count + "'>" + " Software/Hardware: " + "<select name='softhardware_" + count + "'>" + "<option value='' selected>No Choice</option>" + "<cfoutput query='getSoftHard'>" + "<option value='#pk_softwareHardware#'>#pk_softwareHardware#</option>" + "</cfoutput>" + "</select>" + "</td>" + "</tr>" + "</table>"; <!--- Adds Extra fields for Description ---> newdiv.innerHTML = newdiv.innerHTML + "<table class='zpExpandedTable' id='resoltable' cellpadding='3' cellspacing='0'>" + "<tr>" + "<td id='paddingformutli'>" + "Description: " + "</td>" + "<td class='descriptionmoveinmulti'>" + "( You may enter up to 1000 characters. )"+ "<br>" + "<textarea maxlength='1000' onkeyup='return descriptionmaxlength(this)' onkeydown='return descriptionmaxlength(this)'rows='4' cols='60' name='thedescription_" + count + "'></textarea>" + "</td>" + "</tr>" + "</table>"; <!--- Adds Extra fields for Resolution ---> newdiv.innerHTML = newdiv.innerHTML + "<table class='zpExpandedTable' id='resoltable' cellpadding='1' cellspacing='0'>" + "<tr>" + "<td id='paddingformutli'>" + "Resolution: " + "</td>" + "<td class='resolutionmoveinmulti'>" + "( You may enter up to 1500 characters. )"+ "<br>" + "<textarea maxlength='1500' onkeyup='return resolutionmaxlength(this)' onkeydown='return resolutionmaxlength(this)' rows='4' cols='60' name='resolution_" + count + "'></textarea>" + "</td>" + "</tr>" + "</table>"; <!--- Adds Extra fields for Resolution Date, Current Date (for resolution date) and resolution vertified as effective by ---> newdiv.innerHTML = newdiv.innerHTML + "<table class='zpExpandedTable' id='resoldatetab' cellpadding='1' cellspacing='0'>" + "<tr>" + "<td id='paddingformultitop'>" + "Resolution Date: (MM/DD/YYYY) " + "</td>" + "<td>" + "<input type='text' name='resdate_" + count + "' value='' > " + " Current Date: " + "<input type='checkbox' name='currentdateresol_" + count + "' onClick=resdate_" + count + ".value=fill_date()>" + "</td>" + "<td>" + "Resolution Verified as effective by: " + "</td>" + "<td>" + "<select name='resvertified_" + count + "'>" + "<option value='' selected>Make A Selection</option>" + "<cfoutput query='gettech'><option value='#fname# #lname#'>#fname# #lname#</option></cfoutput>" + "</select>" + "</td>" + "</tr>" + "</table>"; <!--- Adds Extra fields for Vertification Date, Current Date (for vertification date) and resolution vertified as effective by ---> newdiv.innerHTML = newdiv.innerHTML + "<table class='zpExpandedTable' id='resoltable' cellpadding='1' cellspacing='0'>" + "<tr>" + "<td id='paddingformultitop'>" + "Verification Date: (MM/DD/YYYY) " + "</td>" + "<td class='vertificationmoveinmulti'>" + "<input type='text' name='vertifidate_" + count + "'> " + " Current Date: " + "<input type='checkbox' name='currentdatevert_" + count + "' onClick=vertifidate_" + count + ".value=fill_date()>" + "</td>" + "</tr>" + "</table>"; <!--- Adds Extra fields for Dept/Vendor Responsibility ---> newdiv.innerHTML = newdiv.innerHTML + "<table class='zpExpandedTable' id='resoltable' cellpadding='1' cellspacing='0'>" + "<tr>" + "<td class='red' id='paddingformultitop'>" + "Dept/Vendor Responsibility*: " + "<select name='deptvendor_" + count + "'>" + "<option value='' selected>Make A Selection</option>" + "<cfoutput query='getDeptVendor'>" + "<option value='#pk_deptVendor#'>#pk_deptVendor#</option>" + " </cfoutput>" + "</select>" + "</td>" + "</tr>" + "</table>"; <!--- Adds Extra fields for RMA Data Only ---> newdiv.innerHTML = newdiv.innerHTML + "<table class='zpExpandedTable' id='resoltable' cellpadding='1' cellspacing='0'>" + "<tr>" + "<td id='paddingformultitop'>" + "RMA Data Only: " + "</td>" + "<td class='rmanmoveinmulti'>" + "( You may enter up to 1000 characters. )"+ "<br/>" + "<textarea maxlength='1000' onkeyup='return rmamaxlength(this)' onkeydown='return rmamaxlength(this)' rows='4' cols='60' name='rma_" + count + "'></textarea> " + "</td>" + "</tr>" + "</table>" + "<input type='hidden' name='"+partc+"' id='"+partc+"' value='0'>" + "<input type='hidden' name='serialcount' id='serialcount' value='" + count + "'>"; <!--- Adds Delete to every ticket ---> newdiv.innerHTML = newdiv.innerHTML + "<table class='zpExpandedTable' id='resoltable' cellpadding='1' cellspacing='0'>" + "<tr>" + "<td>" + "<input type='button' class='removeticket' value='Remove Serial ""+ count +""' onclick=\"removeElement(\'"+divIdName+"\')\"></a>" + "</td>" + "</tr>" + "<tr>" + "<td>" + "<input type='button' class='addticket' value='Add Parts' onclick=\"addpartInput(\'"+divIdName+"\')\">" + "</td>" + "</tr>" + "</table>"; document.getElementById(divName).appendChild(newdiv); } <!---Allows us to remove multiple fields ---> function removeElement(divNum) { var d = document.getElementById('dynamicInput'); var olddiv = document.getElementById(divNum); d.removeChild(olddiv); } </script> <!---Allows us to add PARTS information multiple times---> <script type="text/javascript"> <!---Adds multiple fields for parts ---> function addpartInput(partName){ var parts = document.getElementById(partName); <!---('partsInput')---> <!---this works if only want to add a part under the serial you are working with, but if you have serial information 1 and serial information 2 an want to add information to serial information 1 you cant because parts always appear under the last serial information added if you click add parts---> var getparts = document.getElementById('div'); <!---var avalue = document.getElementById('aValue');---> var serialno = partName.replace("dynamic","").replace("Input",""); var avalue = document.getElementById("partscount"+serialno); <!---var count = (document.getElementById('avalue').value -1)+ 2;---> var count = parseInt(avalue.value) + 1; avalue.value = count; var partdiv = document.createElement('div'); <!---var partIdName = 'part'+count+'Name';---> var partIdName = 'part' + count + 'Name' + serialno; <!---'parts'+count+'Input'---> partdiv.setAttribute('id',partIdName); <!--- Adds Extra fields for parts table ---> partdiv.innerHTML = <!---what used originally for this tableclass='createticketables' id='spaceup'---> "<table class='zpExpandedTable' id='resoltable' cellpadding='1' cellspacing='0' >" + "<th class='sectiontitle' colspan='7'>Parts Information "+ count +" Serial Information "+serialno+"</th>" + "<tr>" + "<td class='indent' id='formfieldpadding'>HC P/N: " + "<input type='text' name='hcpn_" + count + "_"+serialno+"' style='margin:0px'></td>" + "<td class='red'>" + "Parts been returned* " + "<input type='checkbox' name='partsreturn_" + count + "_"+serialno+"' value='1'>" + "</td>" + "<td>" + "<td class='indent'>Defective<input type='checkbox' name='defective_" + count +"_"+serialno+"' value='1'>" + "</td>" + "</td>" + "</tr>" + "</table>"; <!---"<table table class='zpExpandedTable' id='resoltable' cellpadding='1' cellspacing='0' >" + "<tr>" + "<td class='indent' id='formfieldpadding'>Follow up Date:(MM/DD/YYYY) " + "<input type='text' name='followdate_" + count + "' value='' size='8'/> " + "Current Date<input type='checkbox' name='followcheck_"+ count +"' value='' onClick='followdate.value=fill_date()'/></td>" + "<td>On Site:</td>" + "<td><select name='onsite_" + count +"'>" + "<option value='No Choice' selected>No Choice</option>" + "<option value='Yes'>Yes</option>" + "<option value='No'>No</option>" + "</select><td>" + "<td># of Onsite:</td><td><select name='numonsite_" + count +"'>" + "<option value='' selected>No Choice</option>" + "<cfloop from='0' to='10' index='nonsite'><cfoutput>" + "<option value='#nonsite#'>#nonsite#</option></cfoutput></cfloop>" + "</select><td>" + "</tr>" + "</table>"; ---> <!--- Adds Delete to every ticket ---> partdiv.innerHTML = partdiv.innerHTML + "<table class='zpExpandedTable' id='resoltable' cellpadding='1' cellspacing='0'>" + "<tr>" + "<td>" + "<input type='button' class='removeticket' value='Remove Parts ""+count +""' onclick=\"removetheElement(\'"+partIdName+"\')\"></a>" + "</td>" + "</td>" + "</tr>" + "</table>"; document.getElementById(partName).appendChild(partdiv); } <!---Allows us to remove multiple fields---> function removetheElement(divNum) { var d = document.getElementById('partsInput'); var olddiv = document.getElementById(divNum); olddiv.parentNode.removeChild(olddiv); } </script>
Code:<!---Inserts information into serial table.---> <CFIF REQUEST_METHOD EQ "POST"> <CFSET machineListLen = listLen(Form.serialcount)> <CFLOOP from="1" to="#machineListLen#" index="machineCount"> <CFSET serialnum = Form["serialnum_" & machineCount]> <CFSET modelno = Form["modelno_" & machineCount]> <CFSET producttype = Form["producttype_" & machineCount]> <CFSET softhardware = Form["softhardware_" & machineCount]> <CFSET resolution = Form["resolution_" & machineCount]> <CFSET resdate = Form["resdate_" & machineCount]> <CFSET resvertified = Form["resvertified_" & machineCount]> <CFSET vertifidate = Form["vertifidate_" & machineCount]> <CFSET deptvendor = Form["deptvendor_" & machinecount]> <CFSET hardwarefailure = Form["hardwarefailure_" & machineCount]> <CFSET rma = Form["rma_" & machineCount]> <CFSET thedescription = Form["thedescription_" & machineCount]> <!--- <CFSET followdate = Form["followdate_" & machineCount]> <CFSET onsite = Form["onsite_" & machineCount]> <CFSET numonsite = Form["numonsite_" & machineCount]>---> <!--- inserts information into the serial table---> <cfquery name="serial" datasource="CustomerSupport"> exec usp_CS_Insertserial <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">, '#Form.ID#', <cfqueryparam value="#modelno#" CFSQLType = "CF_SQL_VARCHAR">, <cfqueryparam value="#producttype#" CFSQLType = "CF_SQL_VARCHAR">, <cfqueryparam value="#softhardware#" CFSQLType = "CF_SQL_VARCHAR">, <cfqueryparam value="#resolution#" CFSQLType = "CF_SQL_VARCHAR">, <cfqueryparam value="#resdate#">, <cfqueryparam value="#resvertified#" CFSQLType = "CF_SQL_VARCHAR">, <cfqueryparam value="#vertifidate#">, <cfqueryparam value="#deptvendor#" CFSQLType = "CF_SQL_VARCHAR">, <cfqueryparam value="#hardwarefailure#" CFSQLType = "CF_SQL_VARCHAR">, <cfqueryparam value="#rma#" CFSQLType = "CF_SQL_VARCHAR"> </cfquery> <!---Inserts information into notes_descr table.---> <cfquery name="description" datasource="CustomerSupport"> exec usp_CS_Insertdescription <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">, '#Form.ID#', <cfqueryparam value="#thedescription#" CFSQLType = "CF_SQL_VARCHAR">, '#Form.fk_addedBy#' </cfquery> <!---Inserts parts information into parts table.---> <!---because it is a bit we don't use 'ticks' around defective for parts table---> <cfloop from="1" to="#form['partscount' & machinecount]#" index="ps"> <cfparam name="Form.defective_#ps#_#machinecount#" default="0"> <cfparam name="Form.partsreturn_#ps#_#machinecount#" default="0"> <CFSET hcpn = Form["hcpn_" & ps & "_#machinecount#"]> <CFSET partsreturn = Form["partsreturn_" & ps & "_#machinecount#"]> <CFSET defective = Form["defective_" & ps & "_#machinecount#"]> <cfquery name="parts" datasource="CustomerSupport"> exec usp_CS_Insertparts <cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">, '#Form.ID#', <cfqueryparam value="#hcpn#" CFSQLType = "CF_SQL_VARCHAR">, <cfqueryparam value="#partsreturn#" CFSQLType = "CF_SQL_VARCHAR">, <cfqueryparam value="#defective#" CFSQLType = "CF_SQL_BIT">, '#Form.submission#' </cfquery> </cfloop> </CFLOOP> </CFIF>
RachComment
-
Originally posted by acoderIt was actually the Coldfusion code I was looking for. See this line:
Code:<cfloop from="1" to="#form['partscount' & machinecount]#" index="ps">
Well that makes perfect since :). But ok so how do we make it so that parts count or not count missing parts?
Thank you,
RachComment
-
Originally posted by acoderDoes this problem occur when no parts have been added at all or when you add a part and then delete it (leaving no parts)?
It still occurs when i don't add a part. An it happens when i add a part an then delete it.
Thank you,
RachComment
-
<cfloop> has a number of different types. The one you're using here is an index loop. You can also use a conditional loop which might make sense here. You check the condition before entering the loop. See documentation.Comment
-
Originally posted by acoder<cfloop> has a number of different types. The one you're using here is an index loop. You can also use a conditional loop which might make sense here. You check the condition before entering the loop. See documentation.
well the only thing i am worried about the conditional loop is i don't know how many parts they will add or if they will add a part. So would it still work if i had a part or if i didn't have a part? an then if it would work would what i set cfset to. In the example they use <cfset CountVar = 0> do i need to set mine to something like
Code:<cfset ps = "#form['partscount' & machinecount]#">
RachComment
-
You could set ps to 1 then in the cfloop condition, check that it's less than the count. If the count is 0, the code in the loop wouldn't execute.
There's one other approach which may make sense here. It ties in with the second method for deleting parts where you have a list of part numbers. Here you would loop over the list. If the list is empty, it doesn't try to insert parts.Comment
-
Originally posted by acoderYou could set ps to 1 then in the cfloop condition, check that it's less than the count. If the count is 0, the code in the loop wouldn't execute.
There's one other approach which may make sense here. It ties in with the second method for deleting parts where you have a list of part numbers. Here you would loop over the list. If the list is empty, it doesn't try to insert parts.
Well whatever direction you think would be best then all go with that.So if i was to go with the second idea you have how would i go about that.
Thank you,
RachComment
-
Keep a hidden field to list the part numbers separated by commas, i.e. a Coldfusion list, e.g. "1,3,4,5,". This could either be in addition to the count or replace it. In the add parts function, you would add the part number to the field with a comma. In the delete parts function, remove the number from the field. On the Coldfusion side, loop over this list.Comment
-
Originally posted by acoderKeep a hidden field to list the part numbers separated by commas, i.e. a Coldfusion list, e.g. "1,3,4,5,". This could either be in addition to the count or replace it. In the add parts function, you would add the part number to the field with a comma. In the delete parts function, remove the number from the field. On the Coldfusion side, loop over this list.
Hey Acoder,
ok i am mostly confused by the first part. Am i suppose to be creating a hidden field or a coldfusion list like below
Code:<cfset coldfusion_list = "ColdFusion Lists,ColdFusion Arrays,ColdFusion Structures"> <cfloop list="#coldfusion_list#" index="i"> <cfoutput> #i# <br /> </cfloop>
Thank you,
RachComment
-
By hidden field, I meant an input field on the client side, e.g.
Code:<input type="hidden" name="parts1list1" id="parts1list1" value="">
Comment
-
Originally posted by acoderBy hidden field, I meant an input field on the client side, e.g.
Code:<input type="hidden" name="parts1list1" id="parts1list1" value="">
So does it go to the place below or do i need to add it somewhere in the parts function?
Code:<!--- Ticket Information ---> <input type="hidden" value="0" id="theValue" name="theValue"/> <input type="hidden" name="parts1list1" id="parts1list1" value=""> <!---<input type="hidden" value="0" id="aValue" /> ---> <div id="dynamicInput"> <!--- All Ticket Information and Parts information Appears Here---> </div> <input type="button" class="addticket" value="Add Serial" onClick="addInput('dynamicInput');" >
RachComment
Comment