karenn1 Posted August 16, 2007 Share Posted August 16, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/65230-solved-replacing-links/ Share on other sites More sharing options...
Fadion Posted August 16, 2007 Share Posted August 16, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/65230-solved-replacing-links/#findComment-325738 Share on other sites More sharing options...
karenn1 Posted August 16, 2007 Author Share Posted August 16, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/65230-solved-replacing-links/#findComment-325780 Share on other sites More sharing options...
dmdb Posted August 16, 2007 Share Posted August 16, 2007 This should work: <a href="#" onclick="this.style.display='none'; document.getElementById('block').style.display='inline'">Phone</a> <span id="block" style="display:none"><?=$rs_prop["home_no"]; ?></span> Quote Link to comment https://forums.phpfreaks.com/topic/65230-solved-replacing-links/#findComment-325803 Share on other sites More sharing options...
karenn1 Posted August 17, 2007 Author Share Posted August 17, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/65230-solved-replacing-links/#findComment-326475 Share on other sites More sharing options...
karenn1 Posted August 17, 2007 Author Share Posted August 17, 2007 GuiltyGear, or anybody else, do you have any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/65230-solved-replacing-links/#findComment-326578 Share on other sites More sharing options...
MadTechie Posted August 17, 2007 Share Posted August 17, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/65230-solved-replacing-links/#findComment-326582 Share on other sites More sharing options...
karenn1 Posted August 17, 2007 Author Share Posted August 17, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/65230-solved-replacing-links/#findComment-326623 Share on other sites More sharing options...
MadTechie Posted August 17, 2007 Share Posted August 17, 2007 maybe use onmouseover instead of onclick ? Quote Link to comment https://forums.phpfreaks.com/topic/65230-solved-replacing-links/#findComment-326632 Share on other sites More sharing options...
karenn1 Posted August 17, 2007 Author Share Posted August 17, 2007 That works but I'm just a bit concerned. In the end, I want to record how many people are actually clicking or rolling over that link. Can this be done with PHP? Quote Link to comment https://forums.phpfreaks.com/topic/65230-solved-replacing-links/#findComment-326662 Share on other sites More sharing options...
MadTechie Posted August 17, 2007 Share Posted August 17, 2007 both use the same javascript.. (not php) you are aware that the current code will show the phone numbers in the html source, if you want more control from the PHP side you may want to move to an ajax route or have a "full details" popup. Quote Link to comment https://forums.phpfreaks.com/topic/65230-solved-replacing-links/#findComment-326670 Share on other sites More sharing options...
karenn1 Posted August 17, 2007 Author Share Posted August 17, 2007 I'm aware that it's using javascript and that it's showing in the html source but I thought there might be a way to pass this to PHP and record it there, perhaps into a table in a database? Quote Link to comment https://forums.phpfreaks.com/topic/65230-solved-replacing-links/#findComment-326673 Share on other sites More sharing options...
karenn1 Posted August 17, 2007 Author Share Posted August 17, 2007 I found a piece of code that does the trick: href="javascript:void(0);" So I'm keeping it as onClick but I would still like to record those clicks to a database though. Is that possible? Quote Link to comment https://forums.phpfreaks.com/topic/65230-solved-replacing-links/#findComment-326681 Share on other sites More sharing options...
MadTechie Posted August 17, 2007 Share Posted August 17, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/65230-solved-replacing-links/#findComment-326683 Share on other sites More sharing options...
karenn1 Posted August 17, 2007 Author Share Posted August 17, 2007 Okay, I'll try something like that. Thanks for all your help! Quote Link to comment https://forums.phpfreaks.com/topic/65230-solved-replacing-links/#findComment-326691 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.