1

I've recently been designing a website for a client, and have run into a slight difficulty in Javascript - I need to have either a <?php include()?>, or a form (the former being of more use) within a Javascript alert box.

Is there any way to do this? Thanks. :)

2
  • 1
    By Java you mean JavaScript, right? Commented May 11, 2011 at 22:10
  • Do you mean have custom input fields in an alert popup, like the one you get when you do alert("string"); Or like a form in a modal that pops over the rest of the content on the page? Commented May 11, 2011 at 22:11

3 Answers 3

1

The alert function can only show plain text.

You need to use a fake modal dialog, such as jQuery UI Dialog.

Sign up to request clarification or add additional context in comments.

Comments

0

One PHP page:

<script type="text/javascript">
alert("<?php include("otherpage.php"); ?>");
</script>

otherpage.php:

echo "Hello, world";

Of course, the output of otherpage.php can only be plain text, and must have properly escaped quotes. If you need to do anything else, you will need a different solution than JavaScript's alert.

1 Comment

You'd need to be very careful about the output of your PHP include, or capture it and escape it for use in a javascript context.
0

Does it have to be an alert box? Can it not be a lightbox?

The jquery UI dialog box may be of some help. it hasa dialog box with a form

jQuery UI Dialog Box

Personally if you want a form in a box to pop up on click or something I would use a lightbox.

Hope this helps,

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.