Save the content of a text area into a file

How can I replace the input with a textarea?

Using Sinatra-Framework

<form action="/create" method="post">
    <input type="text" name="file" value="<%= @contents %>">
    <input type="submit" value="Save">


<textarea id="text" name="text" rows="25" cols="150"><%=@contents%></textarea>

When the page renders? Use JavaScript (or in this case jQuery).

var $input = $("input[name='file']"),
    contents = $input.val();


var $textArea = $("<textarea />", {
    id: "text",
    name: "text",
    rows: 25,
    cols: 150,
    text: contents


I’m not sure that’s what you mean though :confused:

Hi Pullo,

thank you very much for your help.
I’m sorry but I can’t get it running, because I don’t know how to adapt my Ruby main.rb accordingly.

Please see the inital situation below.

Kind regards

require "sinatra"

get '/create' do
  @logfile ="logfile.txt","r")
  @contents =
  erb :create

post '/create' do
  @logfile ="logfile.txt","w")
  redirect '/create'

see HTML form of my initial post

Sorry, I’m not sure what you’re trying to do.

If you literally just want to replace the input with the text area, do this in views/create.erb

<form action="/create" method="post">
    <textarea id="text" name="file" rows="25" cols="150"><%=@contents%></textarea>
    <input type="submit" value="Save">

Had to change the name of the text area from text to file.

Or can you rephrase your question.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.