|
|
Subject:
Need HTML help - Form Tag
Category: Computers > Internet Asked by: respree-ga List Price: $5.00 |
Posted:
22 Nov 2002 13:39 PST
Expires: 22 Dec 2002 13:39 PST Question ID: 112762 |
Hello: I am having a problem trying to find the correct syntax to this form. I wish to place the text "Search" within the box contained on this page: http://www.respree.com/scstore/sitepages/formtest.html When the user clicks on the box (its a search box), the word "Search" will then disappear, allowing the user to enter the search phrase. Here is the HTML that controls this page. Please tell me the correct syntax to do this. Thanks in advance for your help. HTML appears below. <FORM STYLE="margin-bottom:0;" ACTION="/cgi-bin/SoftCart.exe/cgi-bin/pdbsearch.pl%%softcart.session%%" METHOD="POST"> <DIV ALIGN="left"> <INPUT TYPE="hidden" NAME="addtocart_page" VALUE="/scstore/scpages/showcart.html"> <INPUT TYPE="hidden" NAME="results_page" VALUE="/../pagegen/sresults.html"> <INPUT TYPE="hidden" NAME="max_results" VALUE="12"> <INPUT TYPE="text" SIZE="20" NAME="keywords"> <INPUT TYPE="image" img SRC="/scstore/images/btn-go3.gif" HEIGHT="14" BORDER="0" VALUE="Search" WIDTH="21" ALIGN="MIDDLE" NAME="image"> <!-- END HEADER --> <!-- Search results will be inserted below this line --> <!-- BEGIN FOOTNOTE --> </DIV> </FORM> | |
| |
| |
| |
| |
|
|
Subject:
Re: Need HTML help - Form Tag
Answered By: gan-ga on 22 Nov 2002 18:27 PST Rated: |
Hi respree. Here is the code you will need in order to insert the text 'Search' into your input box, and have it clear when a user clicks on the box: <INPUT id="box" TYPE="text" SIZE="20" NAME="keywords" value="Search" onClick="document.forms[0].box.value=''"> This is to replace the same line number 21, that you already have in your example source code at: http://www.respree.com/scstore/sitepages/formtest.html (Corresponding to line 10 in your code posted in your question, here.) The id= statement attaches an identifying label to your input box, calling it 'box'. If the existing javascript on your page already uses this identifier, you can try a different one. 'box2', 'datain', would be valid choices. Just alter the label to reflect the identifier you use, in the statement later on in that line as well, that says: document.forms[0].box.value Occasionally code posts in such a way as to introduce errors, so you can see a working demonstration of your code at the following page also: http://www.beginnerprogrammer.com/respree.html (use your browser's 'view > source' menu to view the source code.) Search Strategy: Existing knowledge I hope this solution allows you to move on with the design of your page. If you have any queries, please do not hesitate to use the 'request answer clarification' feature before rating my answer - I will be pleased to assist you further. Best regards, gan. | |
| |
|
respree-ga
rated this answer:
Awesome! That worked wonderfully! Thank you so much. |
|
Subject:
Re: Need HTML help - Form Tag
From: darthcow-ga on 22 Nov 2002 23:38 PST |
I would modify the code for best results as noted below... <INPUT TYPE="text" SIZE="20" NAME="keywords" value="Search" onclick="if(this.value=='Search')this.value=''" onblur="if(this.value=='')this.value='Search'"> This solution doesn't bother with the ID attribute and just uses the simpler "this" attribute instead. It preforms a check to make sure the text is still the default value before reseting it (so that one can enter terms, click elsewhere on the page and return) and it also resets it to "Search" if the box is left empty :). |
Subject:
Re: Need HTML help - Form Tag
From: sgtcory-ga on 23 Nov 2002 08:16 PST |
Seems rather bothersome to have it keep coming back - especially if you lose focus on *accident*. It works great, just seems a tad bit like overkill. It seems smart to have an id attribute, in case you want to add the same effect to other forms etc... It will help you keep track of everything easier. One thing is for certain - the search logs for this would show alot of searches for 'Search' :-) Good comment! |
Subject:
Re: Need HTML help - Form Tag
From: respree-ga on 23 Nov 2002 11:18 PST |
Thank you darthcow for your comment. However, it doesn't work exactly how I imagined. When you click into the box, I'd like the text to disappear so the user is free to type their search term. Your solution forces the user to manually erase the text "Search" before entering their search term, which I think is bit cumbersome. Additional comments/solutions are welcome. Thanks. |
Subject:
Re: Need HTML help - Form Tag
From: darthcow-ga on 23 Nov 2002 17:10 PST |
Respree - be sure that you've edited the "Search" value withing the javascript to exactly the default value of the input box. So looking at the example on your site, the code would actually look like this: <input type="text" size="20" name="keywords" value="Search Products" onclick="if(this.value=='Search Products')this.value=''" onblur="if(this.value=='')this.value='Search Products'"> Just to make sure I hadn't made a silly mistake in my code, I put it on a test page and it worked just as I anticipated it (in the IE 6 that I'm running at least, though I don't see why that would be different for other browsers). |
Subject:
Re: Need HTML help - Form Tag
From: respree-ga on 23 Nov 2002 21:34 PST |
Darthcow: My apologies and thanks. I made a silly typo, when I altered the text from "Search" to "Search Products," which lead me to the wrong conclusion. Both yours and gan's solution seem to work equally well. I'm not sure I understand your explanation about how yours performs a check before resetting it. When you say click elsewhere on the page and return, do you mean return to that page using the back button? If so, wouldn't the search term be there anyway, since the back button would display a cached page (with the search term entered) just before the click away from it? If you'd be so kind to explain. Thank you for your help. |
Subject:
Re: Need HTML help - Form Tag
From: sgtcory-ga on 24 Nov 2002 06:14 PST |
respree, The input area *checks itself* for the word Search in your case. If the word Search is present when the person clicks inside the search box, it will be replaced with the value of nothing : if(this.value=='Search')this.value='' <-- Note the value of '' or nothing He's actually manipulating the value of the form value name : Reference to the value --> value="Search Products" In your case you already know that the value on initial page load will be 'Search'. You have no need to use a conditional statement (if) to check the form value. He was just showing another possibility, and it works great. There's probably quite a few more ways you could do it as well : <INPUT NAME="respree" value="Search" TYPE="text" SIZE="20" NAME="keywords" onFocus="respree.innerText=''"> <INPUT TYPE="text" SIZE="20" NAME="keywords" value="Search" onFocus="this.value=''" > Both of those work too :-) Choices, choices, choices.... |
Subject:
Re: Need HTML help - Form Tag
From: respree-ga on 24 Nov 2002 07:25 PST |
Thanks sgtcory for the clarification and additional choices. BTW, do you happen to know if there is a way to control the font color and font type (and size) in these solutions for the text "Search Products?" I tried using the obvious font tags, but it didn't seem to work. Maybe my placement was wrong. |
Subject:
Re: Need HTML help - Form Tag
From: sgtcory-ga on 24 Nov 2002 09:10 PST |
Hello respree - You would typically want to use CSS to control the layout of the fonts within the form. <INPUT style="color: #FF0000; font-family: arial" NAME="respree" value="Search" TYPE="text" SIZE="20" NAME="keywords" onFocus="respree.innerText=''"> Where the added part is : style="color: #FF0000; font-family: arial" To explain this would take a *little* more than a paragraph. You could pose another question to the researchers to get a full explanation. (I would do my best to ensure I answered your question) I hope you understand that I am not trying to draw you in for another question, although that would be great. Our guidelines dictate that we should be as helpful as possible, and at the same time keep the answer at hand in focus. I hope you can relate - as I think you are one of the better customers of the program. Thanks for all the questions! SgtCory |
Subject:
Re: Need HTML help - Form Tag
From: darthcow-ga on 24 Nov 2002 12:47 PST |
Ok, let me explain why I think my code excerpt is the best by explaining how it works line by line. <input type="text" size="20" name="keywords" value="Search Products" The part you already had. onfocus="if(this.value=='Search Products')this.value=''" This performs a check to see if the value of the field is "Search Products" when the box is selected (note that I changed the code from onclick so that it also works when the box is tabbed to :)). Since that's the default value when the page is loaded, you want clicking on it to clear the box. However, if it isn't the default value, then it means that the user has changed the value of the input box. It could be an annoyance if somebody enters some text, then the input box uses focus (e.g. the user goes to another window) and when they try to enter the rest of the text, it clears the text they tried to svae. onblur="if(this.value=='')this.value='Search Products'"> What this checks for is "onblur", when the user leaves the input box to click on something else. If someone clicks on the search box (thereby clearing it) and then clicks away, it's best to have the box return to say "Search" so the purpose of it is known. The if check is there to make sure the box is blank before replacing it with "Search", because otherwise the user could be saving it for something. I don't see any reason why not to use this code because the box still becomes blank again when it's clicked on if the value is "Search". Play around with clicking on the text box and leaving, and entering text in it, and you'll understand how it works. sgtcory has some interesting alternate solutions, but I would recommend against using the one repeated below because the innerText attribute has limited compatability with older browsers (most notably Netscape 4.x): <INPUT NAME="respree" value="Search" TYPE="text" SIZE="20" NAME="keywords" onFocus="respree.innerText=''"> A decent guide to style properties, can be found here - http://www.htmlhelp.com/reference/css/properties.html You can also try a google search for CSS (cascading style sheets) or style sheets. Style sheets can be a useful part of web design, but I would recommend against relying on them too heavilly because of limited support in older browser (again, mainly netscape 4.x). Just using it to manipulate the way a form item looks is fine though. |
Subject:
Re: Need HTML help - Form Tag
From: sgtcory-ga on 24 Nov 2002 17:24 PST |
Great comments darthcow! I really respect alot of the information you have been giving. Of further note with the Netscape issues - I knew this existed, but the truth is in the numbers. Less than 1 percent of all visitors to *most* sites use this browser version or under. I'm not saying we should count them out at all, but we shouldn't design a site based around them either. I think this is indeed where style sheets are effective. You can have one style for IE, and one for Netscape. Again - thanks for the comments. You show some impressive internet skills. Respree - I really like your site. I'm impressed with the overall theme and layout. Keep it up! SgtCory |
Subject:
Re: Need HTML help - Form Tag
From: darthcow-ga on 24 Nov 2002 18:11 PST |
That's OK... I hate Netscape too :D. If I could, I would ignore it, but you always know that some poor fool is still using it. Fortunately, at least Netscape can display most pages (just don't rely completely on CSS for everything possible or it will be completely unreadable in Netscape). |
Subject:
Re: Need HTML help - Form Tag
From: respree-ga on 24 Nov 2002 20:28 PST |
Researchers: Thanks so much for your comments. Your helpfulness and willingness to share your knowledge with the 'technically challenged' is appreciated. I wasn't expecting my $5 to get so much mileage, but am happy I did. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |