473,396 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Cannot Hide layer when text length is zero? Help!

I am trying to hide a layer when a text box length is zero, and its
just not working! It hides the content in the layer, but you still
see a little 2 pixel width blip on the screen. I've spent hours
playing with stuff, its a brain cramp. Need someone to state the
obvious for me. Heres my code.....
<style type="text/css" media="screen">
#search_suggest {
position: absolute;
background-color: #FFFFFF;
text-align: left;
border: 1px solid #3366CC;
}
</style>

<script language="javascript" type="text/javascript">

function OneStrcZeroLength(thelayer){
if ( document.getElementById('txtSearch').length == 0){
thelayer.style.display='none';
}
}
</script>
<form id="frmSearch">
<input type="text" id="txtSearch" name="txtSearch" alt="Search
Criteria" onkeyup="searchSuggest();"
onkeydown="OneStrcZeroLength(document.getElementBy Id('search_suggest'));"
autocomplete="off" />

<input type="submit" id="cmdSearch" name="cmdSearch" value="Search"
alt="Run Search" /><br />
<div id="search_suggest">
</div>
</form>

As you can see from the code, ONKEYDOWN for textbox "txtSearch", it
calls function OneStrcZeroLength, which then checks to see if
txtSearch has a zero length, and if it does, it tells the layer style
to change to display none.

Which it doesn't do. Ive done numerous things to try to correct this,
but to no avail. Any ideas?

Thanks!
JE

Jun 18 '07 #1
5 1527
JEgbert <jo**@onestructure.comwrote in news:1182203250.592225.115890
@w5g2000hsg.googlegroups.com:
I am trying to hide a layer when a text box length is zero, and its
just not working! It hides the content in the layer, but you still
see a little 2 pixel width blip on the screen. I've spent hours
playing with stuff, its a brain cramp. Need someone to state the
obvious for me. Heres my code.....
I could be totally wrong, but maybe two things?

a) could the blip be the 'remnants' of the text cursor? it seems like
you'd be hiding a DIV that has an active, flashing 'text input' cursor.
maybe its a screen redraw issue. try taking the focus() off the
layer/field first?

b) im assuming this isn't it, because you can get '0' right now, but
shouldnt it be:

if ( document.getElementById('txtSearch').value.length == 0) ??

(i added 'value'.. mentally i imagine that getElementById
('textSearch').length is the length of the DOM element, not the field
value. obviously i haven't executed your code)

:)

good luck

Jun 18 '07 #2

JEgbert wrote:
I am trying to hide a layer when a text box length is zero, and its
just not working! It hides the content in the layer, but you still
see a little 2 pixel width blip on the screen. I've spent hours
playing with stuff, its a brain cramp. Need someone to state the
obvious for me. Heres my code.....

try:
<script type="text/javascript">
function OneStrcZeroLength(txtSearch,thelayer){
if (!txtSearch.value.length)
thelayer.style.display='none';
}
</script>
<form id="frmSearch">
<input
type="text"
id="txtSearch"
name="txtSearch"

onkeyup="searchSuggest();OneStrcZeroLength(this,do cument.getElementById('search_suggest'));"
/>

<div id="search_suggest"></div>
</form>

Jun 19 '07 #3
hey guys,
Thanks for the shot.. unfortunately it didnt work, but I know why.....

it DOES hide the layer, but not the layer border. The border still is
1px, regardless of the info in the layer being hidden. if I take out
the border it works.

But I need the border :-) How would I dynamically hide the border?
JE

Jun 19 '07 #4
SPOKE TOO SOON. IT DOESNT WORK. forget everything I just said. none
of this is even hiding anything. Just put some content in the
search_suggest div and check it out for yourself.

Jun 19 '07 #5
JEgbert <jo**@onestructure.comwrote in news:1182282091.816991.260250
@q75g2000hsh.googlegroups.com:
SPOKE TOO SOON. IT DOESNT WORK. forget everything I just said. none
of this is even hiding anything. Just put some content in the
search_suggest div and check it out for yourself.
the code i provide at the end of this post works for me.

i left the "alert" in the function so you can see whats happening. You
ignored my earlier suggestion to leave "value" in there - i put it in
because you weren't checking for the value's length.

I changed the CSS to make it very apparant that the DIV is hiding
correctly.

Also, you were calling searchSuggest as a function which wasn't in the
code until I put something blank in.

Also, i don't know if you REALLY want to be calling your functions when
you do (onkeydown) because you have a fundamental flaw in your logic.
When i want to enter a character in your text box, you're calling the
function before my character is entered, so it reports '0' as the length
even though i just typed a character. Change it to "onkeyup", or better
yet, combine your function into the function searchSuggest.

Surely you can take it from here... after you buy me a beer.

**

<html>
<head>
<style type="text/css" media="screen">
#search_suggest {
position: absolute;
background-color: #FFFFFF;
text-align: left;
border: 1px solid #3366CC;
width: 200px;
height: 400px;
}
</style>

<script language="javascript" type="text/javascript">

function OneStrcZeroLength(thelayer){
//note that you must have 'value' in there!!!
var dox = document.getElementById('txtSearch').value.length;
alert(dox); //see what happens if 'value' is removed for proof
if (dox == 0){
thelayer.style.display='none';
}
}

function searchSuggest() {
//nothing to see here
}

</script>

</head>
<body>

<form id="frmSearch">
<input type="text" id="txtSearch" name="txtSearch" alt="Search
Criteria" onkeyup="searchSuggest();"
onkeydown="OneStrcZeroLength(document.getElementBy Id
('search_suggest'));"
autocomplete="off" />

<input type="submit" id="cmdSearch" name="cmdSearch" value="Search"
alt="Run Search" />
<br />
<div id="search_suggest"></div>

</form>

</body>
</html>
Jun 19 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ryh | last post by:
I have the following scritpt. It hides div layer when mouse is out of the div layer. Inside DIV I have IFRAME box. Unfortuantely it does not work in Mozilla or IE 5.5. It hides div when cursor is...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
0
by: John Mason | last post by:
Hi, I have developed an asp.net application that uses forms authentication. I have a local install and a remotely hosted install of the application. Intermittently the remote application falls...
3
by: Merlin | last post by:
Hi there, I am trying to create a form with an dynamic field that can be shown or hidden. As I saw for example on google it is possible with JS to show a layer and move the content underneath...
2
by: =?Utf-8?B?cmVk?= | last post by:
Hi Friends, We recently deployed our application to production and I am experiencing the below error message. Cannot access a disposed object named "System.Net.TlsStream" The error occurs...
1
by: JEgbert | last post by:
I built a dynamic ajax suggest engine, and you would think I could figure this out, but I am having a brain cramp. When I don't have any characters in the search box, it shows a little blip of the...
1
by: pamate | last post by:
hi, I want to show hide layers. I am able to show and hide layers but i am facing problem that, cant view the cursor in Mozilla,but i can type in input text box, its overlapping the layers. ...
3
by: Coll | last post by:
I inherited a database. On one of the forms, a bunch of fields on the form are to be updated with data from a combo box containing many columns after one particular field is updated. I'm receiving...
12
by: Kevin Blount | last post by:
I'm having a very odd issue, that arose this morning after working fine yesterday... here's a very simple script: 1: <?php 2: $test = $_GET; 3: echo "Hello" . $test . "<p>"; 4: ?>
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.