| | |
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:
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...
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
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.
•
•
Join Date: Sep 2007
Posts: 45
Reputation:
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
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
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.
![]() |
Similar Threads
- Help: Show - Hide (JavaScript / DHTML / AJAX)
- show/hide files in tools/folder options not showing (Windows NT / 2000 / XP)
- 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?
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate array automatically beta box browser bug calendar captchaformproblem cart checkbox close codes column createrange() css cursor date debugger decimal dependent design dom download dropdown element embed enter error events firefox focus form frameworks getselection google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 iframe images index internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsfile jsp libcurl listbox maps masterpage media menu microsoft mimic mp4 onmouseover paypal php player position post problem programming progressbar prototype redirect regex runtime safari scale scriptlets search security select size software sql text textarea unicode w3c website window windowofwords windowsxp






