Jump to content

Recommended Posts

Hey everyone!

 

I've posted this query before but I didn't get my answer. I thought a new topic will produce a new perspective on my problem. I have a list of people and their details (name, telephone number, etc). This is dynamically driven and all info is stored into a database. I don't want the phone number to display at first, instead I want it to be a hyperlink attached to the text "Phone".

 

What I want is when users click that hyperlink, the link get replaced completely with the correct phone number. I basically want this to record how many people are enquiring on a certain phone number. I've got it so far that the link pulls in the correct phone number but how to I replace the link completely with the number (ie, the number is in the place where the link was - no link attached to the number, though)?

 

Can anyone please help?

 

Thanks,

Karen

Link to comment
https://forums.phpfreaks.com/topic/65230-solved-replacing-links/
Share on other sites

U can use url variables for this, so when the link is pressed u pass to the url a link like: profiles.php?phone=true&id=10. Everytime the link is pressed the page refreshes, reads the url variable and makes the changes. Anyway i think this isnt what u want, instead u can use javascript. Place the phone number in an invisible div (or span) with a specified id and make them show like this:

 

<a href=\"javascript://\" onclick="this.style.display='none'; divId.style.display='block'">Phone</a>

 

divId is the id of the div which contains the phone number. If it doesnt work like that use: document.getElementById('divId').style

Thanks for your reply. I've used the javascript like you said. The phone link disappears fine but the invisible span doesn't come up. Here's my code:

 

<a href="#" onclick="this.style.display='none'; document.getElementById('block').style">Phone</a>
<span id="block" style="visibility:hidden"><?=$rs_prop["home_no"]; ?></span>

 

What am I doing wrong?

It works great BUT it only works for the first entry on the list. Any other member on the list, when I click on phone, it's always the first entry phone number that comes up. Here's my code for the while loop I have to display the list:

 

 <?php
		$i = 0;
		while ($rs_prop = mysql_fetch_array($result_prop))	{
	?>
          <tr>
            <td height="27" class="body-text-np" style="padding-left:5px; padding-right:2px;"><input name="checkbox[<?= $rs_prop["id"]; ?>]" type="checkbox" class="style1" onClick="rowHighlight(this.parentElement.parentElement)" value="<?= $rs_prop["id"]; ?>"></td>
            <td class="body-text-np" style="padding-left:5px; padding-right:2px;"><a href="update.php?id=<?= $rs_prop["id"]; ?>" class="style1"><img src="../images/icon_update.gif" width="16" height="16" border="0"></a></td>
            <td class="db_list_text" style="padding-left:5px; padding-right:2px;">
              <?= $rs_prop["name"]; ?>           </td>
            <td class="db_list_text" style="padding-left:5px; padding-right:2px;">
              <?= ucwords($rs_prop["initials"]); ?>            </td>
            <td class="db_list_text" style="padding-left:5px; padding-right:2px;">
              <?= ucwords($rs_prop["address"]); ?>           </td>
            <td class="db_list_text" style="padding-left:5px; padding-right:2px;">
              <?=$rs_prop["house_number"]; ?>            </td>					    
            <td class="db_list_text" style="padding-left:5px; padding-right:2px;">

		<a href="#" onclick="this.style.display='none'; document.getElementById('block').style.display='inline'">Phone</a>
		<span class="db_list_text" style="padding-left:5px; padding-right:2px;"><span id="block" style="display:none"><?=$rs_prop["home_no"]; ?></span>
		</span></td>
            



		<td class="db_list_text" style="padding-left:5px; padding-right:2px;">
              <?= ucwords($rs_prop["email"]); ?>           </td>
            <td class="db_list_text" style="padding-left:5px; padding-right:2px;"><?php if ($rs_prop["amount"] > 0) { print "<img src=\"../images/icon_blueexclamation.gif\" width=\"14\" height=\"14\">";}?></td>
          </tr>
	  <?php $i++; } ?>

 

 

Any ideas? I'm not sure how to modify it.

try changing

			<a href="#" onclick="this.style.display='none'; document.getElementById('block').style.display='inline'">Phone</a>
		<span class="db_list_text" style="padding-left:5px; padding-right:2px;"><span id="block" style="display:none"><?=$rs_prop["home_no"]; ?></span>
		</span></td>

 

to

 

 

			<a href="#" onclick="this.style.display='none'; document.getElementById('<?= $rs_prop["name"]; ?>').style.display='inline'">Phone</a>
		<span class="db_list_text" style="padding-left:5px; padding-right:2px;"><span id="<?= $rs_prop["name"]; ?>" style="display:none"><?=$rs_prop["home_no"]; ?></span>
		</span></td>

 

 

basically giving unique ID's

 

i used $rs_prop["name"] but $rs_prop["ID"] would be better (if it exists) the Unique from the database

I used ID like you suggested and it works like a charm!! Thank you! The other thing, because the link currently goes to #, when I'm halfway down the page and I click on "Phone", it displays the number correctly but the page jumps to the top. I have a list of about 500 members so I don't want that to happen. Just leaving the href as "" doesn't work either. How can I work around that?

personally i would use ajax..

erm..

 

have a popup with for details you could have the

details.php?href='id=<?php echo $rs_prop["id"];'

 

then on the details.php page you use $_GET['id'] to pull all the details of that records id, and then could also update the "counter field" at the same time!

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.