Ruby Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesRuby Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old June 20th, 2007, 12:30 AM
CLEM_C_ROCK CLEM_C_ROCK is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 130 CLEM_C_ROCK User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 21 m 15 sec
Reputation Power: 6
Javascript_tag replacing whitespaces w/ '%20'

Hello,

I have a form that tests if a title has been changed since the page was loaded and the page has been submitted. If the page title has been changed then a confirm box will ask if the user wants to have the title changed. The problem is if the person hits cancel, all white spaces in the title get replaced w/ '%20'.

Here's the code I was using:

Code:
<%=javascript_tag( "function confirmSubmit(){ var page_title_before= '#{u @page.title}';
                                              var page_title_on_submit = escape($('page_title').value);
                                                  if( page_title_before != page_title_on_submit ){
                                                      var agree=confirm('Changing the title of this page will break any links or bookmarks that refer to it.\\nPress \"OK\" to save with the new title, or \"Cancel\" to revert to the original title.');  
                                                 if(agree){ return true; }
                                                                                                 else{  alert( 'page_title_before-->>' + escape(page_title_before) ); $('page_title').value = page_title_before; return false; }
                                                  }
                                              else{ return true; }}") %>

Reply With Quote
  #2  
Old June 20th, 2007, 11:53 AM
L7Sqr L7Sqr is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Location: Constant Limbo
Posts: 577 L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level)L7Sqr User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 8 h 49 m 8 sec
Reputation Power: 67
Send a message via AIM to L7Sqr
It is hard to say without knowing what u does in the following section of code:
Code:
var page_title_before= '#{u @page.title}';

I asume that it escapes the string to match the next line
Code:
var page_title_on_submit = escape($('page_title').value);

Since (again, assuming URI) escape will do:
Code:
irb(main):011:0> s = 'This is a title'
=> "This is a title"
irb(main):012:0> URI.escape s
=> "This%20is%20a%20title"
irb(main):013:0> 


If both of those assumptions hold, then when you do:
Code:
$('page_title').value = page_title_before;
in the cancel case, you assign page_title the escaped version of @page.title
__________________
-- I'll provide you with reference points; if they dont work, refer to something else.

If you process text, this might make your life a little easier.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesRuby Programming > Javascript_tag replacing whitespaces w/ '%20'


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway