Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7637015

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:50:03+00:00 2026-05-31T07:50:03+00:00

I have a PHP code: if($billing_total>$limit_to_send){ echo ‘<script type=text/javascript> window.onload = function() { alert(Sorry,

  • 0

I have a PHP code:

  if($billing_total>$limit_to_send){

    echo '<script type="text/javascript">
    window.onload = function() {
    alert("Sorry, you do not have enough credit");
 }
   </script>';

When I am printing this message, it is being printed at the beginning of the PHP page as below:

  <script type="text/javascript">
                window.onload = function() {
                alert("Sorry, you do not have enough credit");
             }
               </script>

        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        -----------------------------------------------------------

This caused the header (logo) of my page in the browser to move down one line.

and the page will look very bad because all the items there will be moved down one line.

I hope it is clear to you. Please any solution ?

===========================================================================

Thanks for All …

Solution:

$alert_message=<script type="text/javascript">
    window.onload = function() {
    alert("Sorry, you do not have enough credit");
 }
   </script>

Printing $alert_message somewhere in the HTML code before the body tag ^_^

  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:50:05+00:00Added an answer on May 31, 2026 at 7:50 am

    Make sure you never output anything before the DTD (doctype declaration).

    See this question for more information…

    The doctype declaration must be the first element of your html page, it’s from what the browser decides how to handle the rest of the html code. Outputting anything before that will probably put your browser in quirks mode so you can’t be sure how the browser will render your page.


    How to avoid this?

    The echo command gets executed as its line is reached, and it seems that the rest of your html code follows after that.

    You could either

    • move the html DTD and header to the top of your php (but sometimes that is not possible) OR
    • store the error html in a variable, so instead of echo '<script ... do $errorhtml = '<script ... and output that string, if not empty, at a specific place in the head or body generating code of your php.
    • If you have no control over the original source, you could consider redirecting to an error page with its own html DTD, header and body which you can design as fits you best.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this PHP code echo '<a href=# onclick=updateByQuery(\'Layer3\', ' . json_encode($query) . ');>Link
I have PHP code that tries to output JavaScript and I do something like
I have some php code that generates a random password. Next to a text
I have php code like: class Foo { public $anonFunction; public function __construct() {
I am using PHP and JavaScript. My JavaScript code contains a function, get_data(): function
I have this php code, with which I am trying to generate a popup
I have some PHP code that generates dynamic tables of data on the fly.
I have some PHP code that is designed to make a spreadsheet with formulas
I have some PHP code that generates a calendar and then outputs html to
I have following PHP code $val=<div id=user.$row['cid']. userid=.$row['cid']. class=innertxt><img src=images/images.jpg width=50 height=50><strong>.$uname.</strong><ul> <li>Email: .$row['cemail'].</li>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.