Jump to content

Use Message Box in PHP


pbchambers

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/278784-use-message-box-in-php/
Share on other sites

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>

'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.

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>";

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.