Hi folks. I have a form submission that might take a question mark as part of a field. Of course, setting the params variable for an ajax.request will essentially screw it up due to the second question mark in the params string. So I went to regexp and made this function: function cleanQuestion(str) { /* Returns a string with question marks as $#63; */ var myReturn = str.replace(/^\?/, ''?''); return myReturn; } The problem is, it still shows up as a question mark. Anybody know how to get around this? Cheers --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
If you pass it to params as a Hash, you shouldn''t have a problem. e.g. {"name":"value"} If you''re passing it as a string, you may want to encodeURIComponent () on the value portion first. TAG On Jul 1, 2007, at 1:31 AM, BeeRich wrote:> > Hi folks. > > I have a form submission that might take a question mark as part of a > field. Of course, setting the params variable for an ajax.request > will essentially screw it up due to the second question mark in the > params string. > > So I went to regexp and made this function: > > function cleanQuestion(str) { > /* Returns a string with question marks as $#63; */ > var myReturn = str.replace(/^\?/, ''?''); > return myReturn; > > } > > The problem is, it still shows up as a question mark. > > Anybody know how to get around this? > > Cheers > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Your function works. How/when are you firing it? the following responds as expected. <script type="text/javascript"> function cleanQuestion(str) { var myReturn = str.replace(/^\?/, ''?''); return myReturn; } alert(''?''); alert(cleanQuestion(''?'')); </script> but why not use encodeURI? http://www.w3schools.com/jsref/jsref_encodeURI.asp On Jul 1, 2:31 am, BeeRich <beer...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi folks. > > I have a form submission that might take a question mark as part of a > field. Of course, setting the params variable for an ajax.request > will essentially screw it up due to the second question mark in the > params string. > > So I went to regexp and made this function: > > function cleanQuestion(str) { > /* Returns a string with question marks as $#63; */ > var myReturn = str.replace(/^\?/, ''?''); > return myReturn; > > } > > The problem is, it still shows up as a question mark. > > Anybody know how to get around this? > > Cheers--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On 7/3/07, Ian <ian-40m7FdE+PqjQT0dZR+AlfA@public.gmane.org> wrote:> > Your function works. How/when are you firing it? > > the following responds as expected. > > <script type="text/javascript"> > function cleanQuestion(str) { > var myReturn = str.replace(/^\?/, ''?''); > return myReturn; > } > > alert(''?''); > alert(cleanQuestion(''?'')); > </script> > > but why not use encodeURI? > http://www.w3schools.com/jsref/jsref_encodeURI.aspThe function works, but when placed back in the original function, it just places the question mark back in context, so I have not achieved anything. I was told about encodeURIComponent and she works great. Cheers -- BeeRich, Toronto --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---