BOBKUSPE
08-23-2010, 02:01 AM
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
gizmo1650
08-23-2010, 02:40 AM
it would help to see the code, but it is probably a variable conflict, try declaring your variable with the var keyword
Philip M
08-23-2010, 06:54 AM
On the face of it your scripts ought to work:-
<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/javatutors/multiplejava.shtml
http://www.dyn-web.com/tutorials/combine.php
Or you can simply fire a set of functions when the page loads.
<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
BOBKUSPE
08-23-2010, 12:22 PM
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