Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Dec 2008
    Posts
    71
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Question Sequence of Javascripts

    Hi,

    I am using several Javascripts into a html file. Individually all scripts working fine, however when I put them on the onclick event someof them not works.

    Example:

    <html>
    <head>
    <script>
    function one;
    </script>

    <script>
    function two;
    </script>

    <script>
    function three;
    </script>
    </head>

    <body>

    <form type=post action=newfile.asp>
    ....................
    ...................
    ...................
    <input type=submit onclick="one(); two(); three();">
    </form>
    </body>
    </html


    The schema is right? How is the best way to force many scripts working fine?

    Bob

  • #2
    Regular Coder
    Join Date
    Apr 2010
    Posts
    163
    Thanks
    3
    Thanked 25 Times in 25 Posts
    it would help to see the code, but it is probably a variable conflict, try declaring your variable with the var keyword

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,314
    Thanks
    203
    Thanked 2,564 Times in 2,542 Posts
    On the face of it your scripts ought to work:-

    Code:
    <html>
    <head>
    <script>
    alert ("function one");
    </script>
    
    <script>
    alert ("function two");
    </script>
    
    <script>
    alert ("function three");
    </script> 
    </head>
    
    <body>
    
    <form type=post action=newfile.asp>
    ....................
    ...................
    ...................
    <input type=submit onclick="one(); two(); three();">
    </form>
    </body>
    </html>
    There are two reasons why multiple scripts may not work together.

    One (the most likely problem here) is duplication of variable and/or function names. The second script overwrites the first.

    The other cause is multiple onload statements. For more info see

    http://www.javascriptkit.com/javatut...iplejava.shtml
    http://www.dyn-web.com/tutorials/combine.php
    Or you can simply fire a set of functions when the page loads.
    Code:
    <script type="text/javascript">
    window.onload = function() {
    functionOne();
    functionTwo();
    functionThree();
    }
    </script>
    Some of these kids would give their right leg to become a professional footballer. - Talksport

  • #4
    New Coder
    Join Date
    Dec 2008
    Posts
    71
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Hmmm...

    Probably there is a conflict here:
    <html>
    <head>
    <script language="JavaScript">
    function cleanIt(){
    var string=document.form1.pageContent.value;
    string=string.replace(/´/g,'"');
    string2=string.replace(/`/g,'"');
    string3=string.replace(/'/g,'"');
    document.form1.pageContent.value=string;
    document.form1.pageContent.value=string2;
    document.form1.pageContent.value=string3;
    }
    </script>
    <script language="JavaScript">
    function cleanIttitle(){
    var string=document.form1.Title.value;
    string=string.replace(/'/g,"`");
    string2=string.replace(/"/g,'`');
    string3=string.replace(/"/g,"'");
    document.form1.Title.value=string;
    document.form1.Title.value=string2;
    document.form1.Title.value=string3;
    }
    </script>
    <script language="JavaScript">
    function stripx() {
    var txtObj=document.getElementById('pageContent');
    var str=txtObj.value;
    str = str.replace(/\r/g,""); // strip /r
    str = str.replace(/\n/g,"****"); // temp replace /n by a token
    str=str.match(/(Other Resources)(.*)(E-mail this article)/);
    var newstr = str[1] + str[2] + str[3];
    newstr = newstr.replace(/\*\*\*\*/g, "\n");
    document.getElementById('pageContent').value = newstr;
    }
    </script>
    </head>

    <body>

    <form type=post action=newfile.asp>
    <TEXTAREA ID="pageTitle" ROWS=3 COLS=57 > </TEXTAREA>
    <textarea name="pageContent" id="pageContent" cols="117" rows="15">
    </textarea><br>

    <input type=submit onclick="cleanIt();cleanIttitle();stripx();">
    </form>
    </body>
    </html>


    Could someone help me to fix the error?

    Bob


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •