# Checking whether or not scripting is enabled or disabled

**URL:** <https://www.ruby-forum.com/t/checking-whether-or-not-scripting-is-enabled-or-disabled/173107>\
**Category:** Rails\
**Created:** [August 3, 2009, 1:04am UTC](https://www.ruby-forum.com/t/checking-whether-or-not-scripting-is-enabled-or-disabled/173107 "2009-08-03T01:04:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [August 3, 2009, 1:04am UTC](https://www.ruby-forum.com/t/checking-whether-or-not-scripting-is-enabled-or-disabled/173107/1 "2009-08-03T01:04:48Z")

</div>

I’m turning my head around and around on this topic and not many  
searches on the web turn up what I need to do. Here’s the simple issue:

I have an ajax search form that is activated via checkbox/observer:

\<%= check\_box “search”, “info” %\>  
\<%= observe\_field(:search\_info, :on=\>‘click’, :frequency=\>0.25, :update  
=\> :form\_container, :with =\> :search\_info, :url =\> { :action =\>  
:search\_form }) %\>

If they check the box, the search\_form action renders the search form:

def search\_form  
validate\_date\_form  
if params[:search\_info] == “null”  
render :text =\> “”

else  
render :partial =\> “search”  
end  
end

All I want to do is degrade to a normal render if the user has scripting  
disabled. So, if scripting is disabled, the search form should be  
rendered always. If not, then only rendered on checkbox.

How can I do this?

I’m using prototype/scriptaculous so I thought it might have to do with  
providing a check with if request.xhr? is true or not…

Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [August 3, 2009, 1:37am UTC](https://www.ruby-forum.com/t/checking-whether-or-not-scripting-is-enabled-or-disabled/173107/2 "2009-08-03T01:37:38Z")

</div>

Hi Joel,  
On Mon, 2009-08-03 at 01:04 +0200, Alpha B. wrote:

> All I want to do is degrade to a normal render if the user has scripting  
> disabled. So, if scripting is disabled, the search form should be  
> rendered always. If not, then only rendered on checkbox.
> 
> How can I do this?

This is what render |format| is about.

HTH,  
Bill

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [August 3, 2009, 3:12am UTC](https://www.ruby-forum.com/t/checking-whether-or-not-scripting-is-enabled-or-disabled/173107/3 "2009-08-03T03:12:30Z")

</div>

There’s a dozen topics on render … something, none of which talks about  
the issue I’m having. Anyone else want to explain how I can accomplish  
this that can provide more than 7 words?

Many thanks in advance.

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [August 3, 2009, 3:21am UTC](https://www.ruby-forum.com/t/checking-whether-or-not-scripting-is-enabled-or-disabled/173107/4 "2009-08-03T03:21:14Z")

</div>

On Aug 3, 2:12 am, Alpha B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> There’s a dozen topics on render … something, none of which talks about  
> the issue I’m having. Anyone else want to explain how I can accomplish  
> this that can provide more than 7 words?

Instead of loading the form via an ajax request, make it part of the  
initial page. When the page loads, executes some javascript that hides  
the search form. If javascript is disabled then that code doesn’t run  
and so the form isn’t visible, if it is enabled then it will be  
hidden.

Fred

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [August 3, 2009, 3:45am UTC](https://www.ruby-forum.com/t/checking-whether-or-not-scripting-is-enabled-or-disabled/173107/5 "2009-08-03T03:45:21Z")

</div>

Hi Fred,

Thanks mate. I hadn’t thought of a backwards compatible type of an  
approach. I’ll see what I can do.

Take care.

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [August 3, 2009, 5:00am UTC](https://www.ruby-forum.com/t/checking-whether-or-not-scripting-is-enabled-or-disabled/173107/6 "2009-08-03T05:00:39Z")

</div>

Fred, thanks for the help. I was able to do:

\<%= check\_box “search”, “info” %\>  
\<%= observe\_field(:search\_info, :on=\>‘click’, :frequency=\>0.25,  
:update =\> :form\_container, :with =\> :search\_info, :url =\> { :action =\>  
:search\_form }) %\>  
\<% controller.response.content\_type = Mime::HTML%\>

\<%= render :partial =\> ‘search’  
%\>
  

  
\<%= javascript\_tag render( :partial =\> ‘hide\_div.js.rjs’) %\>

And then in the rjs partial I placed:

page.hide :hide\_container

This allowed the search partial to be displayed in the div id for  
hide\_container which is viewable by those without ajax/scripting  
enabled. And the render for rjs hides that partial and the  
checkbox/observer still allows the form to be viewed click/unclick.

It looks fairly clean.

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [August 3, 2009, 5:19am UTC](https://www.ruby-forum.com/t/checking-whether-or-not-scripting-is-enabled-or-disabled/173107/7 "2009-08-03T05:19:21Z")

</div>

For clarity in case someone else finds this topic, the final fixes were:

\_hide\_div.js.rjs

page.hide :hide\_container  
page.show :show\_checkbox

index.html.erb

Advanced Search \<%= check\_box "search", "info" %\>
  
\<%= observe\_field(:search\_info, :on=\>'click', :frequency=\>0.25, :update =\> :form\_container, :with =\> :search\_info, :url =\> { :action =\> :search\_form }) %\>
\<%= render :partial =\> 'search' %\>

\<%= javascript\_tag render( :partial =\> 'hide\_div.js.rjs') %\> \<% controller.response.content\_type = Mime::HTML%\>

This automatically hides the “Advanced Search []” and checkbox for those  
with javascript disabled. These are re-enabled by page.show  
:show\_checkbox which applies to the div id="show\_checkbox.

The page.hide :hide\_container then hides the div for div  
id=“hide\_container” from view for people that use ajax.
