samona Posted September 10, 2008 Share Posted September 10, 2008 Hi, I have written a program in PHP to display some fields from a record in the search results. However, I want to make a link that users can click to view all the fields. I don't want to have to have them go to a new page. I want the additional fields to expand. I think I need JavaScript for that. Please advise? Quote Link to comment https://forums.phpfreaks.com/topic/123627-view-more-link/ Share on other sites More sharing options...
lanmonkey Posted September 10, 2008 Share Posted September 10, 2008 yep, javascript Quote Link to comment https://forums.phpfreaks.com/topic/123627-view-more-link/#findComment-638400 Share on other sites More sharing options...
kratsg Posted September 10, 2008 Share Posted September 10, 2008 The best way to do this is to pull ALL the information you want (even the ones that won't be shown immediately). Then, have a javascript call like so (for example, the last name field is expandable): <html> <head> <style type='text/css'> label.expandable { display: none; } </style> <script type='text/javascript'> function show(){ var x = document.getElementsByTagName('label'); for(i=0;i<x.length;i++){//loop through all inputs if(x[i].className == 'expandable'){x[i].style.display = 'inline';} } } function hide(){ var x = document.getElementsByTagName('label'); for(i=0;i<x.length;i++){//loop through all inputs if(x[i].className == 'expandable'){x[i].style.display = 'none';} } } function expand(){ var button = document.getElementById('expand_button'); if(button.value == "Expand Fields"){show();button.value = "Contract Fields";} else if(button.value == "Contract Fields"){hide();button.value = "Expand Fields";} else {window.alert('Error: an unexpected event has occured.');} } </script> //extra stuff such as things in between head tags, before body tags... //blah... </head> <body> <input type="button" id="expand_button" value="Expand Fields" onclick="expand()"><br><br> <label name="fname" id="fname">First Name: <input type='text' value='John'></label><br> <label name="lname" id="lname" class="expandable">Last Name: <input type='text' value='Doe'><br></label> //add more, etc... //going to where the body ends </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/123627-view-more-link/#findComment-638423 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.