Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using commas in a form field that outputs to a list.

Status
Not open for further replies.

zyzzyva23

Technical User
Mar 20, 2001
1
US
I currently have a request form set up that allows users to make multiple requests by clicking a button to add new fields. The request entries are then output as comma-delimited lists, which are processed using Coldfusion. So far, so good.

The problem is that many of the requests will include a comma in one of the form fields, and thus Coldfusion will assume that everything in the field after the comma is in the next list element. So, where the user might request 3 copies of product A with the notes "Volumes 1, 2 and 3" and 5 copies of product B with the notes "Paper stick," it comes through as 3 copies of product A with notes "Volumes 1" and 5 copies of product B with notes "2 and 3".

I tried fixing this with a replacechars function, which would replace all commas with the ` character (not too likely to be used in a note) and then having Coldfusion convert the ` characters back to commas after pulling the element from the list. This worked for the first field, but the subsequent fields, populated by the addto function, couldn't seem to call it. Any suggestions?

Here's my code:

<script>
// Show/Hide functions for non-pointer layer/objects
function shownon(showobj,TheTop) {
document.all[showobj].style.display = &quot;block&quot;
//I added this to show the button too.
//document.all['layer3'].style.display = &quot;block&quot;
}
function hidenon(hideobj) {
document.all[hideobj].style.visibility = &quot;hidden&quot;
}

function replaceChars(entry) {
out = &quot;,&quot;; // replace this
add = &quot;`&quot;; // with this
temp = &quot;&quot; + entry; // temporary holder

while (temp.indexOf(out)>-1) {
pos= temp.indexOf(out);
temp = &quot;&quot; + (temp.substring(0, pos) + add +
temp.substring((pos + out.length), temp.length));
}
document.thisform.notes.value = temp;
}


//Function to add another Record.....Just modify the strHTML string to add more.
function addmore(Theobj) {
var strHTML
strHTML='<BR><INPUT type=&quot;text&quot; name=&quot;need&quot; size=&quot;3&quot; maxlength=&quot;3&quot;> <select name=&quot;file_type&quot;><option value=&quot;&quot; selected>Select Type of File</option><cfoutput query=&quot;label_names&quot;><option value=&quot;#label_name#&quot;>#label_name#</cfoutput></option></select> <INPUT type=&quot;text&quot; name=&quot;notes&quot; size=&quot;40&quot; value=&quot; &quot; onBlur=&quot;replaceChars(this.value);&quot;>'
document.all[Theobj].insertAdjacentHTML('BeforeEnd',strHTML)
}

</script>

<table>
<TR>
<TD colspan=&quot;3&quot;>Sub-File Labels Requested:</TD>
</TR>
<TR>
<TD>QTY</TD>
<TD>FILE TYPE</TD>
<TD>LABELING NOTE (NEXT VOLUME NUMBER/DETAIL)</TD>
<td> </td>
</TR>
</table>

<FORM action=&quot;_subfile_new.cfm&quot; name=&quot;thisform&quot; onSubmit=&quot;return validateForm(this)&quot; method=&quot;post&quot;>
<INPUT type=&quot;text&quot; name=&quot;need_1&quot; size=&quot;3&quot; maxlength=&quot;3&quot;>
<select name=&quot;file_type_1&quot;>
<option value=&quot;&quot; selected>Select Type of File</option>
<cfoutput query=&quot;label_names&quot;>
<option value=&quot;#label_name#&quot;>#label_name#</option>
</cfoutput>
</select>
<INPUT type=&quot;text&quot; name=&quot;notes_1&quot; size=&quot;40&quot; value=&quot; &quot;>
<A href=&quot;javascript:shownon('layer2','0');&quot;>Add</A>

<div id=&quot;layer2&quot;>
<INPUT type=&quot;text&quot; name=&quot;need&quot; size=&quot;3&quot;>
<select name=&quot;file_type&quot;>
<option value=&quot;&quot; selected>Select Type of File</option>
<cfoutput query=&quot;label_names&quot;>
<option value=&quot;#label_name#&quot;>#label_name#</option>
</cfoutput>
</select>
<INPUT type=&quot;text&quot; name=&quot;notes&quot; size=&quot;40&quot; value=&quot; &quot; onBlur=&quot;replaceChars(this.value);&quot;>
<A href=&quot;javascript:addmore('layer2');&quot;>Add More</A>
</div>
</form>
 
why don't you use cfreplace BEFORE sending the value ?
what happens if you alert the output of replaceChar, do you have the correct value ?
and it's normal if it changes only one value as you call it only once !!!!!

and PLEASE don't post the whole page as if you're vomiting it, cut and paste only the RELEVANT part of it - you'll be more likely to have an answer

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top