Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Running two javascripts on one page

Posted on 2015-01-18
10
Medium Priority
?
213 Views
Last Modified: 2015-01-19
Having these two scripts on the very same page, only the latter one is run.

<script>
$().ready(function() {
      // validate signup form on keyup and submit
      $("#signupForm").validate({
            rules: {
                ...
            }
      });
});
</script>

and

      <script>
      $(function() {
            $('#lennart').avgrund({
                  ...
            });
      });
      </script>

What should be added to get both working?
0
Comment
Question by:Lennart Ericson
  • 4
  • 3
  • 3
10 Comments
 
LVL 6

Expert Comment

by:rjohnsonjr
ID: 40556232
Should the first one be :

$(document).ready(function() {
0
 

Author Comment

by:Lennart Ericson
ID: 40556246
In the script, it is stated as I wrote it. Let me state it: I am a complete and utterly newbie.
0
 
LVL 6

Accepted Solution

by:
rjohnsonjr earned 1000 total points
ID: 40556266
ok,  http://api.jquery.com/ready/  shows the syntax is correct
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Lennart Ericson
ID: 40556277
Sorry, don't understand your statement. Would you be kind enough to explain a nit more.
0
 
LVL 43

Expert Comment

by:Rob
ID: 40556282
What rjohnsonjr is saying is your first script should be changed from

$().ready(function() {

To

$(document).ready(function() {
0
 

Author Comment

by:Lennart Ericson
ID: 40556312
Rob Jurd, thanks for explaining!
rjohnsonjr, Even though it is changed according to the suggestion, it doesn't work.
All experts, Any other suggestion?
0
 
LVL 6

Expert Comment

by:rjohnsonjr
ID: 40556407
I meant to say that the page I posted shows that the syntax you provided is correct also.

I would install chrome browser and use chrome developer tools to see what the javascript errors are.

https://developer.chrome.com/devtools
0
 
LVL 43

Assisted Solution

by:Rob
Rob earned 1000 total points
ID: 40556648
Are you sure the first is not running? What happens if you add an alert()

I.e.

$(document).ready(function() {
    alert("dom is ready");
    // .... rest of your code below
0
 
LVL 43

Expert Comment

by:Rob
ID: 40556650
And certainly get familiar with any of the browsers dev tools as @rjohnsonjr has suggested
0
 

Author Comment

by:Lennart Ericson
ID: 40557542
My problem turned out to be a conflict between the jquery scripts versions I used. When I downloaded the latest version of jquery and installed it and referred to it, the problem was gone.

I hadn't given information in my question about which jquery versions (I actually had two) I was using, so you had no chance to spot the real problem.

Thanks for your efforts.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question