sebastiz
asked on
strings in javascript stalling script
Im trying to output some database values into javascript. Its all going well but I have one awkward problem. I would like to enter a Customer name as one of the output values as well as their email address. Whenever I use the full customer name (called Full) the script fails. This name has spaces in it eg. "Simon Travis" However when I use the customer's username which never has spaces in it, the thing works fine. I suspect this is a function of the fact the the full customer name has spaces in it and the javascript is getting confused. Here is the relevant bit of code : Beneath it is the outputted javascript
Dim cstype As Type = Me.GetType()
Dim i As Integer
Dim popupscript As String
Dim popupscript2 As String
Try
For Each dtrParent In ds.Tables("Table").Rows
i = i + 1
Try
Dim jfunction As String = "function onSmartWinEvent() {var words" & i & " = '<div ><b>" & dtrParent("USER") & "</b></div>'; marker" & i & ".openSmartWindow(words" & i & ");}"
Dim jcentre As String = "map.drawZoomAndCenter(myP oint1, 10);"
Dim jmarker As String = "var marker" & i & " = new YMarker(myPoint" & i & ");"
Dim jaddmarker As String = "marker" & i & ".addLabel('<blink><font color=white face=arial size=2>" & dtrParent("Full") & "</font></blink>');"
Dim jClickforMore = "var _txt = '<div style=width:160px;height:1 00px;><b>" & dtrParent("Email") & "<p><\p>" & dtrParent("Tel") & "<p><\p>" & "</b></div>'; marker" & i & ".addAutoExpand(_txt);"
Dim jcaptureevent As String = "YEvent.Capture(marker" & i & ", EventsList.MouseClick, onSmartWinEvent);"
'Dim joverlay As String = "map.addOverlay(marker" & i & ");"
dt2.Rows().Add(dtrParent(" USER"), dtrParent("pcode"))
popupscript = jfunction
popupscript2 = jmarker & jaddmarker & jClickforMore & jcaptureevent
'& joverlay
Catch ex As Exception
Console.WriteLine(ex.Messa ge)
End Try
For Each dtrChild In dtrParent.GetChildRows(dre )
Dim jmypoint As String = "var myPoint" & i & " = new YGeoPoint(" & dtrChild("latitude") & "," & dtrChild("longitude") & ");"
popupscript = popupscript & jmypoint & popupscript2
'MsgBox(popupscript)
'dt2.Rows().Add(dtrChild(" longitude" ))
Next
Me.ClientScript.RegisterCl ientScript Block(Me.G etType, "PopUpCode" & i, popupscript, True)
Next
Catch ex As Exception
Console.WriteLine(ex.Messa ge)
End Try
function onSmartWinEvent() {var words2 = '<div ><b>CRMEADMIN</b></div>'; marker2.openSmartWindow(wo rds2);}var myPoint2 = new YGeoPoint(51.816,-0.351);v ar marker2 = new YMarker(myPoint2);marker2. addLabel(' <blink><fo nt color=white face=arial size=2>CR Medical</font></blink>');v ar _txt = '<div style=width:160px;height:1 00px;><b>c olinread@b tconnect.c om<p><\p>0 1582 621 851<p><\p></b></div>'; marker2.addAutoExpand(_txt );YEvent.C apture(mar ker2, EventsList.MouseClick, onSmartWinEvent);
Dim cstype As Type = Me.GetType()
Dim i As Integer
Dim popupscript As String
Dim popupscript2 As String
Try
For Each dtrParent In ds.Tables("Table").Rows
i = i + 1
Try
Dim jfunction As String = "function onSmartWinEvent() {var words" & i & " = '<div ><b>" & dtrParent("USER") & "</b></div>'; marker" & i & ".openSmartWindow(words" & i & ");}"
Dim jcentre As String = "map.drawZoomAndCenter(myP
Dim jmarker As String = "var marker" & i & " = new YMarker(myPoint" & i & ");"
Dim jaddmarker As String = "marker" & i & ".addLabel('<blink><font color=white face=arial size=2>" & dtrParent("Full") & "</font></blink>');"
Dim jClickforMore = "var _txt = '<div style=width:160px;height:1
Dim jcaptureevent As String = "YEvent.Capture(marker" & i & ", EventsList.MouseClick, onSmartWinEvent);"
'Dim joverlay As String = "map.addOverlay(marker" & i & ");"
dt2.Rows().Add(dtrParent("
popupscript = jfunction
popupscript2 = jmarker & jaddmarker & jClickforMore & jcaptureevent
'& joverlay
Catch ex As Exception
Console.WriteLine(ex.Messa
End Try
For Each dtrChild In dtrParent.GetChildRows(dre
Dim jmypoint As String = "var myPoint" & i & " = new YGeoPoint(" & dtrChild("latitude") & "," & dtrChild("longitude") & ");"
popupscript = popupscript & jmypoint & popupscript2
'MsgBox(popupscript)
'dt2.Rows().Add(dtrChild("
Next
Me.ClientScript.RegisterCl
Next
Catch ex As Exception
Console.WriteLine(ex.Messa
End Try
function onSmartWinEvent() {var words2 = '<div ><b>CRMEADMIN</b></div>'; marker2.openSmartWindow(wo
I doubt spaces would be the problem but a name like O'Brian would hose this script.
ASKER
How do i get rid of spaces in the SQL script for the Fullname so i can see if this makes a difference?
The SQL is:
SELECT u.UserName as USER, u.FullName as full, u.Postcode AS pcode_orig, LEFT(u.Postcode, LENGTH(u.Postcode) - LOCATE(' ', REVERSE(u.Postcode))) as pcode, u.Tel as Tel, u.Email AS Email, u.Address AS Address, c.CustomerID FROM dict8.Customer c JOIN blabla.`User` u ON c.UserID = u.UserID WHERE u.Postcode IS NOT NULL GROUP BY pcode"
The SQL is:
SELECT u.UserName as USER, u.FullName as full, u.Postcode AS pcode_orig, LEFT(u.Postcode, LENGTH(u.Postcode) - LOCATE(' ', REVERSE(u.Postcode))) as pcode, u.Tel as Tel, u.Email AS Email, u.Address AS Address, c.CustomerID FROM dict8.Customer c JOIN blabla.`User` u ON c.UserID = u.UserID WHERE u.Postcode IS NOT NULL GROUP BY pcode"
Replace(dtrParent("full"), " ","")
ASKER
rdivilbiss:
Your code for getting rid of spaces worked but you're right, the script still doesnt work. How do I get rid of the apostrophes eg in o'brien, in a sentence that is surrounded by " and also uses '
Also would other punctuation like ( and / and - and . cause problems?
The statement ive got is:
"SELECT u.UserName as USER, REPLACE(u.FullName,' ' ','') as phull, u.Postcode AS pcode_orig, LEFT(u.Postcode, LENGTH(u.Postcode) - LOCATE(' ', REVERSE(u.Postcode))) as pcode, u.Tel as Tel, u.Email AS Email, u.Address AS Address, c.CustomerID FROM blabla.Customer c JOIN dict8.`User` u ON c.UserID = u.UserID WHERE u.Postcode IS NOT NULL GROUP BY pcode"
Seb
Your code for getting rid of spaces worked but you're right, the script still doesnt work. How do I get rid of the apostrophes eg in o'brien, in a sentence that is surrounded by " and also uses '
Also would other punctuation like ( and / and - and . cause problems?
The statement ive got is:
"SELECT u.UserName as USER, REPLACE(u.FullName,' ' ','') as phull, u.Postcode AS pcode_orig, LEFT(u.Postcode, LENGTH(u.Postcode) - LOCATE(' ', REVERSE(u.Postcode))) as pcode, u.Tel as Tel, u.Email AS Email, u.Address AS Address, c.CustomerID FROM blabla.Customer c JOIN dict8.`User` u ON c.UserID = u.UserID WHERE u.Postcode IS NOT NULL GROUP BY pcode"
Seb
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.