•
•
•
•
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
![]() |
•
•
Join Date: Sep 2007
Posts: 31
Reputation:
Rep Power: 2
Solved Threads: 1
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)
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...
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...
Use the 'id' of the element to do the same.
javascript Syntax (Toggle Plain Text)
var s = document.getElementById('results').style; var b = document.getElementById('buttonId'); if(!s || !b) return; b.onclick = function() { s.display = 'none'; };
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.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
•
•
Join Date: Sep 2007
Posts: 31
Reputation:
Rep Power: 2
Solved Threads: 1
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.
Thanks though
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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- show/hide files in tools/folder options not showing (Windows NT / 2000 / XP / 2003)
- Help: Show - Hide (JavaScript / DHTML / AJAX)
- Hide and unhide web objects (VB.NET)
- Center Div in Browser (JavaScript / DHTML / AJAX)
- visibility & disable (JavaScript / DHTML / AJAX)
- Hide all DIV's On Click (JavaScript / DHTML / AJAX)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: javascript print in landscape
- Next Thread: AJAX Beginner's Book Recommendation?



Linear Mode