rahardi
rahardi

Reputation: 213

trigger two text field in rails at the same time

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

Upvotes: 0

Views: 436

Answers (1)

tokland
tokland

Reputation: 67850

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.

Upvotes: 0

Related Questions