We help IT Professionals succeed at work.

Why is my page adding commas to my values using repeat region?

zippyuk
zippyuk asked
on
Hi,

I have a repeat region, and within that region I have three dynamic values (in a table) which I get from my db.

Here they are:

<td width="25%"><b><font face="Arial, Helvetica, sans-serif" size="2"><%=(rsSoftwaredets.Fields.Item("fnSoftware").Value)%> </font></b></td>
<td width="25%"><b><font face="Arial, Helvetica, sans-serif" size="2"><%=(rsSoftwaredets.Fields.Item("fnSoftFinger").Value)%> </font></b></td>
<td width="26%"><b><font face="Arial, Helvetica, sans-serif" size="2"><%=(rsSoftwaredets.Fields.Item("fnSoftLicence").Value)%>

I need to email these three values so I use a hidden variable within this table  to increment each value which is shown in the table.  To do this I put the following in a hidden field:

<input type="hidden" name="hfList" value="<%=(rsSoftwaredets.Fields.Item("fnSoftware").Value)%><%=(rsSoftwaredets.Fields.Item("fnSoftFinger").Value)%><%=(rsSoftwaredets.Fields.Item("fnSoftLicence").Value)+="\r\n"%>">

This works fine, the next page formats the body of the email using Request objects to get the data entered here, and then sends it using CDO.  The only problem I have is that after the first entry a comma appears after the fnSoftware value.  This is an example (whats in the email):

 Finger Print:
 1-2-3 for Windows
 S1001078
 1
 , Global Network Dialer
 S1401062
 509
 , WinHELP Video Kit for Windows
 S4599008
 10

You see, the ", " which is added to the front of the last two entrys?  This is not in the entry in the database and I can't understand why it keeps adding  this to my entrys.

Thanks for any help in advance.

P.S I know this seems a bit petty but it's really doing my brain in.
Comment
Watch Question

Commented:
Need to see more, show the code that generates the email please...
CERTIFIED EXPERT

Commented:
As far as I can see from the code, you have the same name on all the hidden fields. The values of all the fields are returned in the form or querystring object in one string, comma separated.

You have to add a key or something to the name of the fields, so you get the result in different strings:

<input type="hidden" name="hfList<%=rstSoftwaredets("Id")%>" value="<%=rsSoftwaredets("fnSoftware")%><%=rsSoftwaredets("fnSoftFinger")%><%=rsSoftwaredets("fnSoftLicence")%>

Or add all the values into one big string and put in a single hidden field:

strList=""
While not rstSoftwaredets.EOF
   ' html for the table here...
   strList=strList & rstSoftwaredets("fnSoftware") & rstSoftwaredets("fnSoftFinger") & rstSoftwaredets("fnSoftLicence")
   rstSoftwaredets.MoveNext
Wend

%>
<input type="hidden" name="hfList" value="<%=strList%>">
<%
Mark FranzProject Manager
CERTIFIED EXPERT

Commented:
I agree, post the code you use to create the email.

Green, the use of the field name in the example is not an issue as long as the code is looped through with a For Each..Next or a Do While..Loop.  But what you are suspecting might be something, if an array is being created inadvertently by default the , will be used as a seperator.
CERTIFIED EXPERT

Commented:
To clarify, this code:

<input type="hidden" name="hfList" value="alpha">
<input type="hidden" name="hfList" value="beta">
<input type="hidden" name="hfList" value="gamma">

Will produce a result such, that if you on the recieving page uses:

Response.Write Request("hfList")

it will show:

alpha, beta, gamma

See?
Michel SakrRounded IT Consultant / Projects manager / Cloud Consultant / IT Planning
CERTIFIED EXPERT

Commented:
Alle the values are fetched from a field with the same name as said..

Author

Commented:
go.asp - Email code

// Format mail

var mailFormat = "";
var spacer = " ";
var newLine = "\n";
mailFormat += Request.Form("hfFirstname");
mailFormat += spacer;
mailFormat += Request.Form("hfLastname");
mailFormat += spacer;
mailFormat += "has used iRequire and is indicating that the project being developed will potentially require the following software:";
mailFormat += newLine;
mailFormat += newLine;
mailFormat += Request.Form("hfList");
mailFormat += spacer;
mailFormat += newLine;
mailFormat += "Do we have sufficient licences to support this need if it gets approved?";
mailFormat += newLine;
mailFormat += "Regards ";
mailFormat += Request.Form("hfFirstname");
mailFormat += spacer;
mailFormat += Request.Form("hfLastname");
mailFormat += " Tel:(";
mailFormat += Request.Form("hfTelno");
mailFormat += ")";

if (String(Request("Submit")) != "undefined")
{
var objCDO = Server.CreateObject("CDONTS.NewMail");
objCDO.From = "iRequire"
objCDO.To = "K.Abbott@btinternet.com"
objCDO.cc = ""
objCDO.Subject = "Request for software"
objCDO.Body = mailFormat;
Request.Form("hfFirsnamet"); Request.Form("hfLastname");
objCDO.Send()
objCDO = null
Response.Redirect("../personalloggedin.asp")
}

All values are requested from the previous page.
CERTIFIED EXPERT

Commented:
CERTIFIED EXPERT
Commented:
This line:

mailFormat += Request.Form("hfList");

gives you a comma separated list of all the hfList fields. Loop through the form item to get the separate fields:

var List=Request.Form("hfList");
for (i=1; i<=List.Count; i++) {
   mailFormat += List(i);
   mailFormat += newLine;
}
Mark FranzProject Manager
CERTIFIED EXPERT

Commented:
Do not use the + to CAT a string, it leads to unpredictable results.

And what are you doing?  Is this JScript or JavaScript?  If you are trying to run JavaScript client-side you know this will fail, this will run server-side and as long as CDONTS is installed will work;

<%
mailFormat = ""

mailFormat = Request.Form("hfFirstname")&"nbsp;"& Request.Form("hfLastname") & vbCrLf _
& "has used iRequire and is indicating that the project being developed will potentially require the following software:" & vbCrLf _
& vbCrLf _
& vbCrLf _
& Request.Form("hfList") & vbCrLf _
& vbCrLf _
& "Do we have sufficient licences to support this need if it gets approved?" & vbCrLf _
& vbCrLf _
& "Regards " & vbCrLf _
& Request.Form("hfFirstname")&"nbsp;"&Request.Form("hfLastname") & vbCrLf _
& " Tel:nbsp;"&Request.Form("hfTelno") & vbCrLf _
& vbCrLf

if Request("Submit") <> "undefined" Then

Set objCDO = Server.CreateObject("CDONTS.NewMail")
objCDO.From = "iRequire"
objCDO.To = "K.Abbott@btinternet.com"
objCDO.cc = ""
objCDO.Subject = "Request for software"
objCDO.Body = mailFormat
' Don't know what these are doing here...
'Request.Form("hfFirsnamet") Request.Form("hfLastname")
objCDO.Send
Set objCDO = Nothing
Response.Redirect("../personalloggedin.asp")

%>

Of course you will have to include your loop for each iteration.
CERTIFIED EXPERT

Commented:
Mgfranz, clearly it's JScript. Some use it on the server side. In JScript you use + to concatenate strings.

And your code will still include the commas in the mail, as this line:

& Request.Form("hfList") & vbCrLf _

will get a comma separated string of all the hfList fields.
Mark FranzProject Manager
CERTIFIED EXPERT

Commented:
Not if you put it in a For..Each loop and get rid of the If..Then, that's why I mentioned the need to include the loop.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.