User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 456,234 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,762 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 3038 | Replies: 2 | Solved
Reply
Join Date: Sep 2007
Posts: 31
Reputation: verbob is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
verbob verbob is offline Offline
Light Poster

show/hide element by name

  #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)

echo "<p id=\"results\" name=\"".$info['username']."\">";
....
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...
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 7,012
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 25
Solved Threads: 368
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: show/hide element by name

  #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.

Happiness corrupts people.

Failing to value the lives of others cheapens your own.
Reply With Quote  
Join Date: Sep 2007
Posts: 31
Reputation: verbob is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
verbob verbob is offline Offline
Light Poster

Re: show/hide element by name

  #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.

function confirmuser(user) {
	htmlRequest = ajaxFunction();
	var params = "user="+user;
	var getid = document.getElementById(user);
	if (htmlRequest==null){ // If it cannot create a new Xmlhttp object.
		alert ("Browser does not support HTTP Request");
		return;
	} 
	htmlRequest.open('POST', 'confirmuser.php');
	htmlRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	htmlRequest.setRequestHeader("Content-length", params.length);
	htmlRequest.setRequestHeader("Connection", "close");
	htmlRequest.onreadystatechange = function() {//Call a function when the state changes.
	if(htmlRequest.readyState == 4 && htmlRequest.Status == 200) {
		getid.style.display = 'none';
		}
	}
	htmlRequest.send(params); 
}

Thanks though
Last edited by verbob : Nov 16th, 2007 at 1:52 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 5:07 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC