Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > BOOK: Beginning JavaScript
|
BOOK: Beginning JavaScript
This is the forum to discuss the Wrox book Beginning JavaScript by Paul Wilton; ISBN: 9780764544057
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning JavaScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 10th, 2004, 02:17 PM
Registered User
 
Join Date: Jul 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default text box active with cursor in it upon opening

I need Javascript that I can insert to make the text box in a search form active, with the cursor already in it, so the user doesn't have to click on it to make it active before entering text.
Below is the HTML for the simple search box. Much appreciative
<body>

<p>Search Page:</p>

<!--webbot bot="Search" S-Index="All" S-Fields S-Text="Search for:" I-Size="50"
S-Submit="Start Search" S-Clear="Reset" S-TimestampFormat="%m/%d/%y" TAG="BODY" b-useindexserver="0"
-->

<input type=button value="Back" onClick="history.go(-1)">

</body>
 
Old July 10th, 2004, 04:09 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

<body onload='setFocus()'>
<script type='text/javascript'>
function setFocus()
{
 document.forms.f.inputbox.focus();
 document.forms.f.inputbox.select();
}
</script>
<form id='f' ...>
<input id='inputbox' type='text'/>
</form>
</body>

HTH,

Snib

<><
 
Old July 10th, 2004, 09:25 PM
Registered User
 
Join Date: Jul 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks but I still have to work with it. Whenever I get to the:
function setFocus()
{
document.forms.f.inputbox.focus();
document.forms.f.inputbox.select();
}
I give an syntax error. Perhaps I missed something or I dont have it in the right line as it seems like valid script. I work it again tommorow.
 
Old July 11th, 2004, 02:07 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Can I see the code of your page?

Thanks,

Snib

<><
 
Old July 12th, 2004, 08:46 AM
Registered User
 
Join Date: Jul 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I appreciate your personal input. As you requested I am posting the script as I last left it.

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Search Page</title>
<meta name="Microsoft Border" content="tlb, default">
</head>

<body onload='setFocus()'>
<script type='text/javascript'>
function setFocus()
{
document.forms.f.inputbox.focus();
document.forms.f.inputbox.select();
}

</script>
<form id='f ...>
<input id=' type='text' inputbox'/>


<p>Search Page:</p>
<p>Use this page to search for text within this website.&nbsp;</p>
<p>To refine you search and avoid wading through irrelevant pages, be fairly specific
and avoid common connecting words such as &quot;of - the -and - a - as&quot;
etc.</p>
<!--webbot bot="Search" S-Index="All" S-Fields S-Text="Search for:" I-Size="50"
S-Submit="Start Search" S-Clear="Reset" S-TimestampFormat="%m/%d/%y" TAG="BODY" b-useindexserver="0"
-->

<input type=button value="Back" onClick="history.go(-1)">
</form>
&nbsp;</body>

</html>

I would like to understand what went wrong
Thanks
 
Old July 12th, 2004, 08:58 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

You seem to have randomly left out parts of it, and scrambled it around a little.

This:

<form id='f ...>

Should be:

<form id='f' ...>

Also, the '...' is where you should put other attributes, like the action, etc.

<input id=' type='text' inputbox'/>

Should be:

<input type='text' id='inputbox'/>

Fix these and it should work.

Hope this Helps,

Snib

<><
 
Old July 19th, 2004, 04:40 PM
Registered User
 
Join Date: Jul 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks
It works I must be somewhat Dyslexic as I seem to have a hard time recognizing my own mistakes. I need a proof reader.
 
Old July 19th, 2004, 08:09 PM
Registered User
 
Join Date: Jul 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well it kind of worked but I wound up with a second input box and lost the search feature, BUT the cursor was active in the second input box. Oh the joy.
Somewhere I have a book on javascript, if I can find it I may figure it out.

 
Old August 18th, 2004, 09:54 AM
Registered User
 
Join Date: Aug 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is complete code , which works fine
enjoy!!!!
 " document.f.search.focus();" search the name of text box

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Search Page</title>

<meta name="Microsoft Border" content="none, default">
</head>

<body onload="setFocus()">
<script type="text/javascript">
function setFocus()
{
document.f.search.focus();
document.f.search.select();
}

</script>
<form name='f'>

<p>Search Page:</p>
<p>Use this page to search for text within this website. </p>
<p>To refine you search and avoid wading through irrelevant pages, be fairly specific
and avoid common connecting words such as "of - the -and - a - as"
etc.</p><form action="_vti_bin/shtml.dll/search1.htm" method="POST"><input type="hidden" name="VTI-GROUP" value="0"><p><b>Search for: </b><input type="text" name="search" size="50" value></p><p><input type="submit" value="Start Search"><input type="reset" value="Reset"></p></form>

<input type="button" value="Back" onClick="history.go(-1)">
</form> </BODY></HTML>


karthik

 
Old September 1st, 2004, 11:57 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

Dont put ur <script> within body! It must be in <head> exactly when u wanna call a function from that! otherwise its ok, what browser u use?

Always:),
Hovik Melkomian.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Put cursor at the end of input text peace2007 Javascript 1 October 11th, 2007 04:49 AM
How to show the Active Status Box? karwaabhi ASP.NET 2.0 Professional 0 February 7th, 2007 06:59 AM
Set cursor at specific location in text box pritz VB How-To 3 August 29th, 2005 10:27 AM
Set cursor at specific location in text box pritz Beginning VB 6 1 August 15th, 2005 12:22 PM
Text box and cursor in it (netscape) maz JSP Basics 0 September 9th, 2004 12:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.