show/hide element by name

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Sep 2007
Posts: 45
Reputation: verbob is an unknown quantity at this point 
Solved Threads: 1
verbob verbob is offline Offline
Light Poster

show/hide element by name

 
0
  #1
Nov 15th, 2007
I would like to "hide" everything encompassed in a particular <p> tag that is 'named' by a variable(created a php script that reads from the db and echo's a users details in a <p> that has the name of the 'member number' via a variable - user. (yes it sounds a bit weird....not easy to explain)

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. echo "<p id=\"results\" name=\"".$info['username']."\">";
  2. ....
  3. echo "</p>";

The above works just fine. The elements name is infact the 'username'. I have passed the variable back to html document as 'user' (yes, I verified that it is the correct value in the variable as it is passed to another php script via ajax and returns the appropriate result)

What I need to do is when I click a button, the contents within the specific <p></p> are set to display:none . The problem I am having is that the elements 'name' is only known by a variable - 'user'. ....I hate coding DOM related functions lol...
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,600
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 462
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: show/hide element by name

 
0
  #2
Nov 16th, 2007
Use the 'id' of the element to do the same.
  1. var s = document.getElementById('results').style;
  2. var b = document.getElementById('buttonId');
  3. if(!s || !b)
  4. return;
  5. b.onclick = function() {
  6. s.display = 'none';
  7. };
Last edited by ~s.o.s~; Nov 16th, 2007 at 1:14 pm.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 45
Reputation: verbob is an unknown quantity at this point 
Solved Threads: 1
verbob verbob is offline Offline
Light Poster

Re: show/hide element by name

 
0
  #3
Nov 16th, 2007
I just changed things a couple hours ago and echo'd a div with the 'username' as the id before the <p> element, then referenced that id in the onreadystatechange of an ajax function(calls an update to the database when a button is clicked) to set it to hidden once the update is complete.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function confirmuser(user) {
  2. htmlRequest = ajaxFunction();
  3. var params = "user="+user;
  4. var getid = document.getElementById(user);
  5. if (htmlRequest==null){ // If it cannot create a new Xmlhttp object.
  6. alert ("Browser does not support HTTP Request");
  7. return;
  8. }
  9. htmlRequest.open('POST', 'confirmuser.php');
  10. htmlRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  11. htmlRequest.setRequestHeader("Content-length", params.length);
  12. htmlRequest.setRequestHeader("Connection", "close");
  13. htmlRequest.onreadystatechange = function() {//Call a function when the state changes.
  14. if(htmlRequest.readyState == 4 && htmlRequest.Status == 200) {
  15. getid.style.display = 'none';
  16. }
  17. }
  18. htmlRequest.send(params);
  19. }

Thanks though
Last edited by verbob; Nov 16th, 2007 at 1:52 pm.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC