I am making an HTML5 page with multiple forms. Each input box has its own submit button to convert the temperature unit into another (Celsius to Kelvin, etc.). What tags or attributes do I need to make the submit button focus when its input box is focused or typed in by the user? Javascript (made from coffeescript) is used in this file. There is no CSS.
-
2You have only one element focused at a time. What do you mean for a button to be focused while its input is focused?– Konstantin DinevCommented Jun 26, 2013 at 11:00
-
If you want to allow for press enter to submit a form, then you can add keyboard event to the input box.– jcubicCommented Jun 26, 2013 at 11:08
-
Pressing enter on focused input will trigger submit event on a form. You don't need any extra attributes.– claustrofobCommented Jun 26, 2013 at 11:09
Add a comment
|
2 Answers
You can use javascript for this write onfocus="hilight(form_number);" on each input box. and in your function you can hilight the button
<form name="form1">
<input type="text" onfocus="hilight(1)" />
<input type="submit" id="btn_1" class="button" />
</form>
<form name="form2">
<input type="text" onfocus="hilight(2)" />
<input type="submit" id="btn_2" class="button" />
</form>
<form name="form1">
<input type="text" onfocus="hilight(3)" />
<input type="submit" id="btn_3" class="button" />
</form>
<script>
function hilight(opt)
{
document.getElementById('btn_'+opt).style('','');//you can add any styles to button here
}
</script>
-
there is no css function in javascript, it's jQuery function. In pure javascript you use style attribute, which is an object.– jcubicCommented Jun 26, 2013 at 11:23
Have you tried using the onblur event of the input box to set the focus to the respective submit?