pbchambers Posted June 5, 2013 Share Posted June 5, 2013 I am a new user to this forum, so apologies if this has been dealt with before, but I can't find any info I am writing a web site to generate SMS messages to sets of users in a MYSQL database. I want the user to list the names of the people in a selected set eg. Men or Women BUT I want to have it so that when any name on that list is clicked then a popup box will display the mobile number of that person. I tried using echo "<a href = '#' onclick='javascript: alert('".$row['Mobile']."')>".$row['Name']."</a><br>"; which displays the names as links but won't activiate the popup. I think it is because it is recalling the whole page which loses everything Any ideas or help most appreciated. I am happy to post the whole page later if it helps Quote Link to comment https://forums.phpfreaks.com/topic/278784-use-message-box-in-php/ Share on other sites More sharing options...
gristoi Posted June 5, 2013 Share Posted June 5, 2013 one direction you could take is something like this: have a select list of all users with the name as the select option and the value as the mobile: <select id="names"> <option value="077451452584">Bob Bob</option> <option value="077451452585">Frank Frank</option> <option value="077451452586">Bertha Bertha</option> </select> <script> $(document).ready(function(){ $('#names').on('change', function(){ var val = $('option:selected', this).val(); alert(val); }); }); </script> Quote Link to comment https://forums.phpfreaks.com/topic/278784-use-message-box-in-php/#findComment-1434215 Share on other sites More sharing options...
ginerjm Posted June 5, 2013 Share Posted June 5, 2013 'javascript: alert('".$row['Mobile']."')>".$row['Name']."</a><br>"; Don't use an <a> tag to host your onclick, just make it a <span>. Also convert to a js function call like this. <script type="text/javascrpt"> function showMe(num,nam) { alert('For: ' + name + " Mobile #: "+num); return; } </script> in your html: echo "<span onclick='showMe(\"". $row['Mobile']. "\",\"" . $row['Name'] ."\")'>$row['Name']</span>"; Now you are just executing JS and not making any kind of html action. Quote Link to comment https://forums.phpfreaks.com/topic/278784-use-message-box-in-php/#findComment-1434217 Share on other sites More sharing options...
Solution cpd Posted June 5, 2013 Solution Share Posted June 5, 2013 (edited) Out of interest, why would you want to popup every time the select something. As and end user that would be so flaming annoying its untrue. You're code wont work due to how you're closing the onclick attribute. You need to be careful when echoing javascript. This will work: echo "<a href=\"#\" onclick=\"javascript: alert('".$row['Mobile']."');\">".$row['Name']."</a><br>"; Edited June 5, 2013 by cpd Quote Link to comment https://forums.phpfreaks.com/topic/278784-use-message-box-in-php/#findComment-1434218 Share on other sites More sharing options...
pbchambers Posted June 6, 2013 Author Share Posted June 6, 2013 Thank you! This solution has given me a quick and effective answer to my problem. It now works just as I want. Just to clarify, what I was wanting was for an authorised user to be able to list the names of the people the SMS would go to. I didn't want all the numbers displayed but if they wanted to check a number in the list, clicking on a name would popup the relevant number. I realise that this is not a security measure (they can see all the numbers by viewing the source) but it is a convenience measure for authorised users only to see the number if they needed to check it. Thanks to all for your help! Quote Link to comment https://forums.phpfreaks.com/topic/278784-use-message-box-in-php/#findComment-1434425 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.