File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes alert is not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "alert is not working" Watch "alert is not working" New topic
Author

alert is not working

Jagdeep Sharma
Ranch Hand

Joined: May 24, 2010
Posts: 121

guys,

I am having a sample code. Which is not running properly. It displays instead of alert. My code is below.

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
The browser does not understand that the script tag in the alert is not the closing tag.

Instead of looking at the html code, lets look at some JavaScript.

Your problem is equivalent to



See the issue there? We want the whole string, but it chops it off early at the ' after Eric and throws an error. In the case of the HTML it stops it at the script tag in the code and than renders whatever else as text on the page.

So how would be fix the JavaScript example? We would escape the '




And it would work fine.

What we need to do for the HTML issue is to break up the script tag into two parts.




The browser will no longer see the closing script tag when it is rendering the page.

Eric
Jagdeep Sharma
Ranch Hand

Joined: May 24, 2010
Posts: 121

Eric Pascarello wrote:The browser does not understand that the script tag in the alert is not the closing tag.

Instead of looking at the html code, lets look at some JavaScript.

Your problem is equivalent to



See the issue there? We want the whole string, but it chops it off early at the ' after Eric and throws an error. In the case of the HTML it stops it at the script tag in the code and than renders whatever else as text on the page.

So how would be fix the JavaScript example? We would escape the '




And it would work fine.

What we need to do for the HTML issue is to break up the script tag into two parts.




The browser will no longer see the closing script tag when it is rendering the page.

Eric




You may be right. But if i remove xhtml doctype and use



It works. Now i am unable to understand what is happening here.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
So you are saying you changed it to look like:



I would still expect issues there.
Jagdeep Sharma
Ranch Hand

Joined: May 24, 2010
Posts: 121

Eric Pascarello wrote:So you are saying you changed it to look like:



I would still expect issues there.



Remove doctype. It will work.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
And what horrible browser is this?

In the end you need the doc type on the page.

Eric
Jagdeep Sharma
Ranch Hand

Joined: May 24, 2010
Posts: 121

Eric Pascarello wrote:And what horrible browser is this?

In the end you need the doc type on the page.

Eric


As far as i know. if you use html not xhtml. You dont need doctype. Please correct if i am wrong. Please help. If you remove doctype the code above displays alert box.
 
jQuery in Action, 2nd edition
 
subject: alert is not working
 
Similar Threads
Ajax foriegn word issue
Simple MooTools $$ Selector Problem
Different image reload in the page when i click in the refresh(f5)
Having Problems with Jquery.
Cannot see the JavaScript code I wrote when I hit script tab on firebug :(