Jump to content

[SOLVED] get div to disappear (onclick)


xdanryan

Recommended Posts

I'm relatively new to Javascript/AJAX but I have some decent experience in PHP.

 

What I have been successful at doing is creating a text input that queries a database and narrows down options (basically a simple suggestion). The 'suggestions' are displayed in the div known as "txtHint". When I mouseOver the suggestions, they are auto filled in my text input which is great. What I'm trying to do is get the "txtHint" div to disappear onClick- basically getting rid of the 'suggestions' when I click one.

 

If possible, I'd also prefer a solution that would have the div "txtHint" come back when i add to the text input. I'm assuming if I can get the clear function to work that this would happen anyway.

 

Here's my html code:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script src="test.js"></script>
</head>

<body>

<form>
<input id="users" type="text" onkeyup="showUser(this.value)">
</form>
<p>
<div id="txtHint">
</div></p>

</body>
</html>

 

test.js code (just the clear function)


function clear()
{
   
   document.getElementById("txtHint").value = 'none';
}


 

php code: (random stuff edited out)


//populate table
while($row = mssql_fetch_array($result))
{
echo "<tr><td><a href=\"#\" onmouseover=\"populate('" . $row["CODE"] . "');\" onclick=\"clear();\">" . $row["CODE"] . "</a></td></tr>";
}


?>

 

I've tried a TON of different methods that i found searching google but nothing seems to be working.

Link to comment
Share on other sites

div's don't use value, they use innerHTML

 

function clear()
{
   
   document.getElementById("txtHint").innerHTML = '';
}

Would probably work for your example.

 

Already tried it. Didn't work. No response when I click.

 

my code:

function clear()
{
   document.getElementById("txtHint").innerHTML = '';
}

 

Could the fact that the div is dynamix (AJAX) have something to do with it?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.