Browse the Ruby on Rails Community.

You are here: Forums Ask a Rails expert Submit in Layouts...

Replytotopic

Submit in Layouts

Posted in Forums : Ask a Rails expert

 
Profile

Authority 12
Posting Rating 0
Sign in to rate this post

Hi, I’m a newbie,

I have a layout, with some buttons at the top of the layout, the form is then rendered within the layout. I would like the submit and cancel buttons within the layout and not the form.

The buttons call a function submitbutton(buttonpressed), the problem is I don’t know how to change MyForm

function submitform(buttonpressed){ if (pressbutton) { document.MyForm.task.value=buttonpressed; } if (typeof document.MyForm.onsubmit == “function”) { document.MyForm.onsubmit(); } document.MyForm.submit();
}

Any help appreciated.

 
Profile

Authority 0
Posting Rating 0
Sign in to rate this post

Well, you could change the function to something like this, of course modifying it to fit your situation, and add in the individual id’s of the forms:

JS:

function submitForm(formid) {
document.getElementById(formid).submit();
}

HTML

<form id="blah">

 
Me_version_2

Authority 37
Posting Rating 94
Sign in to rate this post

If you have included the prototype javascript library, you can also have your buttons call:

onclick=”$(‘my-form-id’).submit()”’

Which is basically a shorthand for the same idea that Charles mentioned. Make sure you put an “id” attribute on your form for this to work.

Replytotopic

Other Recent Topics

Ask a Rails expert : Couldn't find Product without an ID

Ask a Rails expert : HTML to XML ---> get title & description

Ask a Rails expert : Accessing controller actions from scripted page?

Ask a Rails expert : seledted option for select_tag

Ask a Rails expert : Merging fields from two tables into one, including duplicates

Ask a Rails expert : saving has_many :through

Ask a Rails expert : Use Rails to develop sites for both Designer and Programmer

Ask a Rails expert : Rails+RS232

Ask a Rails expert : Is this a good way to add Admin section

Ask a Rails expert : RSS feed maker in rails 2.1

Formatting Help
  • *bold*       _italics_      
    bq. (quotes)
  • "DSC":http://www.dsc.net
  • * or # (lists)
or cancel