# Javascript\_tag replacing whitespaces w/ '%20'

**URL:** <https://www.ruby-forum.com/t/javascript-tag-replacing-whitespaces-w-20/107268>\
**Category:** Rails\
**Created:** [June 19, 2007, 9:32pm UTC](https://www.ruby-forum.com/t/javascript-tag-replacing-whitespaces-w-20/107268 "2007-06-19T21:32:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![clemrock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c57346/32.png) [@clemrock](https://www.ruby-forum.com/u/clemrock)\
**Post date:** [June 19, 2007, 9:32pm UTC](https://www.ruby-forum.com/t/javascript-tag-replacing-whitespaces-w-20/107268/1 "2007-06-19T21:32:02Z")

</div>

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:

\<%=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; }}”) %\>
