Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Focus and Text Boxes

Status
Not open for further replies.

itnassol

Technical User
Nov 6, 2006
3
GB
Hi,

I have a framed page with a text box in the top frame, the text box inserts a record in the database, then displays it on the bottom frame, whet i want to do is, after the insert force the focus back to the text box. ie user 1 enter data into the text box and clicks submit, the page stay and the text box is empty, but the cursor is flashing in the text box, at the moment you have to click o the tect box every time you want to make an entry

Any help would be good thanks

Andrew
 
Insert this into your body tag
Code:
onload="window.document.yourform.yourformelement.focus();"
After changing yourform & yourformelement to the correct values, ie the name of your form and the field you wish to set focus on

[Peace][Pipe]
 
Thanks for that, but it does not seem to be working, here is the code i am using,
<body>

<form action="<?php echo $editFormAction; ?>" method="POST" name="form1" class="style1">

<p>
<input name="textfield" type="text" size="100" onload="window.document.form1.textfield.focus();" autocomplete="off">
<input type="submit" name="Submit" value="Submit" onload="window.document.form1.textfield.focus();">
<input name="hiddenField" type="hidden" value="<?php echo $UserName ?>">
<input type="hidden" name="MM_insert" value="form1">
<input name="hfDate" type="hidden" id="hfDate" value="<?php echo date('d/m/Y'); ?>">
<input name="hfTime" type="hidden" id="hfTime" value="<?php echo date('G:i'); ?>">
</p>
</form>

Any ideas why its not keeping focus after i click submit?

Thanks

Andrew
 
You need to add it the body tag.
Code:
<body onload="window.document.form1.textfield.focus();">

<form action="<?php echo $editFormAction; ?>" method="POST" name="form1" class="style1">
  
  <p>
    <input name="textfield" type="text" size="100" autocomplete="off">
    <input type="submit" name="Submit" value="Submit">
    <input name="hiddenField" type="hidden" value="<?php echo $UserName ?>">
    <input type="hidden" name="MM_insert" value="form1">
    <input name="hfDate" type="hidden" id="hfDate" value="<?php echo date('d/m/Y'); ?>">
    <input name="hfTime" type="hidden" id="hfTime" value="<?php echo date('G:i'); ?>">
</p>
</form>
You will also need to ensure that the page is reloaded, as I dont know what your form action is doing I cant comment on that.

[Peace][Pipe]
 
Thanks for that, i think i am being a bit dumb here, i have done that and it still does not work, let me tell you what i am doing in a little more detail.
I have a framed page, the top frame is the textbox and the submit button, this simply takes the text and posts it to the DB. the bottom frame reads the DB and displayed the input, the bottom frame refreshes every now and then, however the top frame does not start with the text box in focus. Also should the (window.document) part of that line be my window name and page name? sorry, very new to all of this and i really appreciate your help
Thanks
Andrew
 
Try using this in your top frame body tag
Code:
onload="document.frames['top'].form1.textfield.focus();"
You need to make sure that the insert action is set to come back to the same page. You could maybe put this in a javascript function that also called for the bottom frame to be reloaded so that everytime a record is inserted the results are reflected.

[Peace][Pipe]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top