-3

I have a html page with a button whos onclick calls a javascript function...but I have been getting a function not defined error for two days! Can someone help?

<!DOCTYPE html>
<html>

        <head>
                 <meta charset="utf-8">
                 <link rel="stylesheet"  href="css/jquery.mobile-1.2.1.css" />
                 <link rel="stylesheet" href="css/jqm-docs.css"/>

                 <script src="js/jquery-1.7.1.min.js"></script>
                 <script src="js/jqm-docs.js"></script>
                 <script src="js/jquery.mobile-1.2.1.js"></script>
                 <script>
                      function doSomething(){
                         alert('this is a test');
                      }
                </script>
         </head>
         <body>
           <div data-role="dialog">    
                <div data-role="content" id = "test" data-theme="c">
                <a href="$callback" data-role="button" data-theme="b" onClick = "doSomething();return true;" rel = "external">$confirm</a>
               <a href="#" data-role="button" data-rel="back" data-theme="c">Cancel</a>    
               </div>
          </div>
         </body>
</html>
9
  • 6
    Why are all those quotes escaped? Commented Sep 6, 2013 at 13:34
  • the entire thing is in a perl script, thats why. in the scipt its print" <html>....</html>"; Commented Sep 6, 2013 at 13:35
  • this is pretty enough onClick = \"doSomething();\" Also you have a href with that a tag. This may affect. Commented Sep 6, 2013 at 13:36
  • 5
    Your browser doesn’t “see” Perl and does therefor not care for it, and neither do we. You want to discuss a client-side problem, so please show the client-side code as well, and not something server-side. Commented Sep 6, 2013 at 13:36
  • 4
    Well then it is invalid HTML. Commented Sep 6, 2013 at 13:42

2 Answers 2

0

This might be handy:

http://jquerymobile.com/demos/1.2.0/docs/pages/page-scripting.html

You need to stick your scripts within the page element:

<div data-role="page">
    <script>
        function doSomething(){
            alert('this is a test');
        }
    </script>
    <!-- the rest of your stuff -->
</div>
Sign up to request clarification or add additional context in comments.

1 Comment

thankyou!!! I had to put the javascript within the PAGE element of the parent of the dialog box. thanks a lot !
0

In fact i have passed personally with this error even with valide HTML all what you need to do is move all of your functions to the head element.

Here is a fiddle:

http://jsfiddle.net/WekEA/1/

To demonstate what i have said in the framework & change the NoWrapToHead to onload

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.