Jump to content

[SOLVED] Putting a variable into a confirm box


cliftonbazaar

Recommended Posts

I have the following code

  <?PHP //Now let's remove the village
  $message = "Do you really wish to delete the village of ". $village_name."?";
  echo "<TD align=center><B>
    <input type=button onclick=show_confirm($message) Value='Remove Village'>
    </B></TD>";
?>

but the show_confirm() will not accept the variable as an argument :(  I have tried ('$message') and ("$message") but I can't get it too work.

 

Note that if I put the word 'message' into show_confirm it displays the word message fine.

Link to comment
Share on other sites

Are you saying that the PHP is not being parsed....in that area?

 

It should work just fine...the code you have.  If you can echo the $message then you should definitely be able to do it as you are already.

 

The problem may lie in your Javascript show_confirm() function.

Have you tried using a simple alert($message)

 

Show us your show_confirm() function

Link to comment
Share on other sites

This is the function as is

  <script type="text/javascript">
  function show_confirm($message)
  {
    var r=confirm($message);
    if (r==true)
    {
      document.write("You pressed OK!");  //TODO change it
    }
  }
  </script>

 

I can echo the variable correctly.

Link to comment
Share on other sites

Please try this. I think you need to exit the echo to get the $message to work.

 

Also when the page renders look in the source, What is in confirm()??

 

<?php 
  $message = "Do you really wish to delete the village of ". $village_name."?";

echo "<TD align=center><B>
    <input type=button onclick=show_confirm(".$message.") Value='Remove Village'>
    </B></TD>";
?>

Link to comment
Share on other sites

What I have done so far -

 

I put show_confirm('message') and the word message came up in a pop up box - like it should, so I know the function works.  In the page source it says onclick=show_confirm('message')

.

 

I change it to show_confirm('message me') and it doesn't work - so I have to assume that the problem is that it doesn't like the space.

 

Link to comment
Share on other sites

Indeed it doesn't ... it's effectively calling show_confirm(village name) which javascript won't understand.

 

Try changing the line to onClick="show_confirm('".$message."')" and you should be OK.

 

No, the page source comes up as this but it won't call the function

onclick=show_confirm('Do you really wish to delete the village of Worcester?')

 

If I change the variable to

$message = "Do-you-really-wish-to-delete-the-village-of-". $villages_array[$i*5]."?";

then it works perfectly, the spaces are giving me the problems.

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.