Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/123627-view-more-link/
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/123627-view-more-link/#findComment-638423
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.