Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6131727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:00:46+00:00 2026-05-23T17:00:46+00:00

How do I create an preview field for auto_html? My controller: def new @post

  • 0

How do I create an preview field for auto_html?

My controller:

  def new
    @post = Post.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @post }
    end
  end

def preview
  post = Post.new(params[:comment])
  render :text => post.body_html
end

My view:

<%= form_for(@post) do |f| %>
  <% if @post.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>

      <ul>
      <% @post.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :titel %><br />
    <%= f.text_field :titel %>
  </div>
  <div class="field">
    <%= f.label :body_html %><br />
    <%= f.text_area :body_html %>
  </div>
  <div class="field">
    <%= f.label :up_votes %><br />
    <%= f.text_field :up_votes %>
  </div>
  <div class="field">
    <%= f.label :down_votes %><br />
    <%= f.text_field :down_votes %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>
<div id="post-preview" style="width:400px;border:1px solid black; height:500px;"></div>

I want to make an preview of the title and the body_html.
Example the a user types “Hello helloe helloe” in the body_html text_area it would instant gets previewed in a div below.

There was an example of this feature here: http://rors.org/2010/08/15/auto_html.html
But it does not work anymore.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:00:47+00:00Added an answer on May 23, 2026 at 5:00 pm

    To do it on the client-side, just use an onfocus on the textbox element which will create an event listener. This function will set another event listener which will activate on keydown and activate another function. This final function will run whenever the user types something, and will access the contents of the textbox and put it into the preview div.

    <!DOCTYPE html>
    <html>
    <head>
    <script type="text/javascript">
    function keypressed(form) {
      text = form.textbox.value
      //do any processing on text desired
      preview.innerHTML = text; 
    }
    
    </script>
    </head>
    <body>
    <form name="myform" action="blah.cgi">
    <input type="text" id="textbox" name="textbox" onkeydown="keypressed(this.form);"/>
    <input type="submit" value="submit" />
    </form>
    <br />
    <br />
    <div id="preview">
    </div>
    </body>
    </html>
    

    Sending it off to the server is amazingly inefficient, unless you’re doing syntax highliting, in which case you could send it off every 10 seconds or so.

    P.S. By the way, if you want to do the auto_html stuff, you can occasionally send it off to the server to do that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a listBox: http://blog.wekeroad.com/blog/aspnet-mvc-preview-using-the-mvc-ui-helpers/ The Html.ListBox doesn't work: <div class=editor-field> <%
I am trying to create an addon with the new addons builder preview (https://builder.addons.mozilla.org/),
What command line util can i use to create a thumbnail preview of a
Create a new appdomain, setup the assemblyResolve handler and you always get an exception
I'm trying to split an HTML string by a token in order to create
I am trying to create a search text-field like on the Apple website .
I'm currently using ImageMagick's convert command to create text preview (.png) from .ttf font
I got a ASP.NET MVC 2.0 Preview 1 app and started to create some
the problem is that how to create a preview of the home screen or
I want to create a preview image before the actual form upload. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.