Jump to content

Use Message Box in PHP


pbchambers
Go to solution Solved by cpd,

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
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>
Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Solution

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 by cpd
Link to comment
Share on other sites

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!

Link to comment
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.