943,557 Members | Top Members by Rank

Ad:
Nov 29th, 2008
0

Javascript web forms without click

Expand Post »
Normally, arriving at a PHP page with a data entry web form, you would have to click on any field you wish to change to go into data entry mode (the first field or any successive one), and then you can tab between fields (TAB to go forward or ALT-TAB to go back one or so) and then to activate the submit button you would only need to press enter.
What I'm wondering, is if upon arrival at the page you can bypass any mouse click at all, and just use the tab key and enter data for any field (perhaps just 2 out of 10), and then still requiring the enter key to submit the data.
So basically this would eliminate the need to click on any field first to start the data entry mode,
Is this possible? And also, if this is an easy fix, can I choose which field is highlighted first (where the tab key would point to) and perhaps add some coloration highlight to the active field at the time?
Thanks
The form code would start out (in the old manual way) as something like this:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <form action="depts.php" method="POST">
  2. Department number: <input type=text name="num" value="" size="2">
  3. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  4. Description: <input type=text name="text" value="" size="20"><br>
  5. Starting Sales: <input type=text name="startr" value="" size="12">
  6. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  7. Ending Sales: <input type=text name="endr" value="" size="12">
  8. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  9. Purchases: <input type=text name="purch" value="" size="12"><br>
  10. Credits: <input type=text name="credit" value="" size="12">
  11. &nbsp;&nbsp;&nbsp;&nbsp;
  12. Book Figure: <input type=text name="book" value="" size="12">
  13. &nbsp;&nbsp;&nbsp;&nbsp;
  14. Cost Markup % <input type=text name="factor" value="" size="5">
  15. &nbsp;&nbsp;&nbsp;&nbsp;
  16. <input type=submit name="submit" value="submit"><br><br>
Last edited by frank754; Nov 29th, 2008 at 1:28 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
frank754 is offline Offline
23 posts
since Oct 2008
Nov 29th, 2008
0

Re: Javascript web forms without click

You have to just set the focus to the first input box after the page is loaded. And that can be done by simple javascript code.

Write an event-handler for <body onload="setInputFocus()">

javascript Syntax (Toggle Plain Text)
  1. function setInputFocus() {
  2. var focusEl = getElementById('1_input');
  3. focusEl.focus();
  4. }

And your HTML code will also change a lil bit as you have to set a id for first input you want to focus onload.

html Syntax (Toggle Plain Text)
  1. <form action="depts.php" method="POST">
  2. Department number: <input id="1_input" type=text name="num" value="" size="2">
  3.  
  4. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  5. .
  6. .
  7. .
  8. .
Reputation Points: 83
Solved Threads: 61
Posting Pro in Training
Luckychap is offline Offline
442 posts
since Aug 2006
Nov 30th, 2008
0

Re: Javascript web forms without click

Thanks a lot, I had to play with it a bit, but got it to work just fine. In the head section I put:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2. function SetInputFocus() {
  3. document.getElementById('1_input').focus();
  4. }
  5. window.onload = SetInputFocus;
  6. </script>
And then changed the form below to add the element name as you mentioned.
I also did a color mod which I found on this page:
http://www.netmechanic.com/news/vol5...cript_no19.htm
So all is looking great!
Appreciated your quick reply
Frank
Reputation Points: 10
Solved Threads: 1
Newbie Poster
frank754 is offline Offline
23 posts
since Oct 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: get size of image file in K , Kb and restrict uplaod if file size is above speci
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Problem Using innerHTML





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC