0

I have these two form with text field (I have a problem with the formatting in this editor, so the symbol of < is not written.


%form_tag(:controller => 'mycontroller', :action => :myaction, :id => @my.id) do
input class="mine" name="mine" type="text" size="10"
input class="his" name="his" type="text" size="10"
%end%


and in the controller, i have

def myaction
mine = params[:mine]
his = params[:his]

if (mine=="") or (his=="")
puts "error"
else

if (mine)
puts "textfield1"
end

if (his)
puts "textfield2"
end
end

I am confused with this. I need to put in each text field a value, and get the result of "textfield1" and "textfield2".
But I recogn that if I press enter in the first textfield (mine), I will go to "textfield1" only.
Is it possible to have in textfield 1 and textfield2 and get both condition executed with just one enter pressed (does not matter I am in the textfield1 or textfield2, but both will be executed if I press enter)?

Thank you for your help

rahardi
  • 213
  • 1
  • 5
  • 12
  • Use {} icon for formating code, not "". Last one is for citing. – gertas Jan 10 '11 at 13:16
  • try putting a button by pressing it you can call both events. – Harry Joy Jan 10 '11 at 13:16
  • If nothing has been filled into the second field, nothing will be submitted. What is it that you expect to receive in this situation? – polarblau Jan 10 '11 at 13:18
  • I expect to show an error message if the second textfield is blank. So I want to get both value of both textfields at the same time (without any field is blank) – rahardi Jan 10 '11 at 14:03

1 Answers1

0

If you need to submit both text fields use a single form. Any other solution would be an unnecessary hack.

[edit] Some browsers don't submit a form when enter is pressed if there is no submit button. Check this question. As some answers say, you can try to hide it if you really want no button.

Community
  • 1
  • 1
tokland
  • 66,169
  • 13
  • 144
  • 170
  • I tried to put both text field in the same form, but it caused that the enter did not work – rahardi Jan 10 '11 at 13:45
  • @rahardi, update the question with that code. No reason enter does not work regardless the input fields the form includes. – tokland Jan 10 '11 at 14:25
  • I have updated it, does not work though.. I tried putting a button as harry said, and it works now. thank you – rahardi Jan 11 '11 at 09:18
  • @rahardi: answer updated, I wasn't aware of that, the webkit browsers I use always submit on ENTER regardless there is a submit button or not. – tokland Jan 11 '11 at 10:15