| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Form value with apostrophe
Do not use standard common code
response.write("<input name=Nameform value=" & oRs.Fields("Name") & "'>") If you try to display the default value in form from database field "Name" it will not wok properly with names containing apostrophe or quotes. O'Briens apears in form as O Instead use that code which is a result of help "icoombs" and "Shadow Wizard" moderators of this forum. All thanks to him. Not to me. Code:
response.write("<input name=Nameform value='" & apostropheASCreplace(quotreplace(trim(oRs.Fields("Name")))) & "'>")
Function apostropheASCreplace(strValue)
If Not IsNull(strValue) Then
strValue = Replace(strValue, "'", "'")
End If
apostropheASCreplace = strValue
End Function
Function quotreplace(strValue)
If Not IsNull(strValue) Then
strValue = Replace(strValue, """, """)
End If
quotreplace = strValue
End Function
code works with 1) apostrophe: O'Briens >>>> O'Briens 2) pair of quotes: "something" >>> "something" 3) combination of apostrophe and quotes: "O'Briens" >>>> "O'Briens" and even ''tes'ts'' ss's comes as ''tes'ts'' ss's NOTE it does not work with unpaired quote like test "someting will come as test but it should not be logically an unpaired quote in text or name as each opened quote must be closed. Ideally we should use regexp to block input of unpaired quotes into database. Last edited by Bron : October 26th, 2009 at 11:44 AM. Reason: testing showed mistakes. now fixed. |
![]() |
| Viewing: ASP Free Forums > Programming > Code Bank > Form value with apostrophe |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|