Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-23-2010, 02:01 AM   PM User | #1
BOBKUSPE
New Coder

 
Join Date: Dec 2008
Posts: 71
Thanks: 8
Thanked 0 Times in 0 Posts
BOBKUSPE is an unknown quantity at this point
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
BOBKUSPE is offline   Reply With Quote
Old 08-23-2010, 02:40 AM   PM User | #2
gizmo1650
Regular Coder

 
Join Date: Apr 2010
Posts: 163
Thanks: 3
Thanked 25 Times in 25 Posts
gizmo1650 is on a distinguished road
it would help to see the code, but it is probably a variable conflict, try declaring your variable with the var keyword
gizmo1650 is offline   Reply With Quote
Old 08-23-2010, 06:54 AM   PM User | #3
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,035
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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
Philip M is online now   Reply With Quote
Old 08-23-2010, 12:22 PM   PM User | #4
BOBKUSPE
New Coder

 
Join Date: Dec 2008
Posts: 71
Thanks: 8
Thanked 0 Times in 0 Posts
BOBKUSPE is an unknown quantity at this point
Hmmm...

Probably there is a conflict here:
<html>
<head>
Quote:
<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>
Quote:
<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>
Quote:
<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
BOBKUSPE is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:51 AM.


Advertisement
Log in to turn off these ads.