This is a discussion on How to call a .js file in my form? within the JavaScript Programming forums, part of the Programming & Scripting category; Hi everyone, i have a show/hide(showhide1.js) file that contains javascript function in it. Each function is for a specific drop ...
| |||||||
|
#1
| |||
| |||
| Hi everyone, i have a show/hide(showhide1.js) file that contains javascript function in it. Each function is for a specific drop down list on a form(myform.asp) and there are many drop down list in my form, instead of writting many funtions in my form i want it to called an external page by using the include feature. I have use this bit in my form but i am not sure what is wrong as i am getting a pop up error message : Code: <script type="text/javascript" src="showhide1.js"></script> Last edited by dtz; March 17th, 2009 at 11:17 AM. |
|
#2
| ||||
| ||||
| What is the error message? When you view the source of the page when loaded in the browser, do you see the <script></script> tag?
__________________ Join the folding team |
|
#3
| |||
| |||
| Quote:
this i what come up when i try to preview the page: ![]() When i click yes, it opens up but ignores the function from showhide1.js ![]() |
|
#4
| ||||
| ||||
| hi post code of showhide1.js file here.
__________________ Love is physical attraction and mental destruction |
|
#5
| |||
| |||
| Hi, this is my .js file Code: <script type="text/javascript"><!--
var lastDiv = "";
function showDiv(divName) {
// hide last div
if (lastDiv) {
document.getElementById(lastDiv).className = "hiddenDiv";
}
//if value of the box is not nothing and an object with that name exists, then change the class
if (divName && document.getElementById(divName)) {
document.getElementById(divName).className = "visibleDiv";
lastDiv = divName;
}
}
//-->
var lastDiv1 = "";
function showDiv1(divName) {
// hide last div
if (lastDiv1) {
document.getElementById(lastDiv1).className = "hiddenDiv1";
}
//if value of the box is not nothing and an object with that name exists, then change the class
if (divName && document.getElementById(divName)) {
document.getElementById(divName).className = "visibleDiv1";
lastDiv1 = divName;
}
}
//-->
</script>
<style type="text/css" media="screen"><!--
.hiddenDiv {
display: none;
}
.visibleDiv {
display: block;
border: 1px grey solid;
}
.hiddenDiv1 {
display: none;
}
.visibleDiv1 {
display: block;
border: 1px grey solid;
}
-->
</style>
|
|
#6
| ||||
| ||||
| hi u are setting lastDiv value blank.u are trying to access element which has id blank. document.getElementById(lastDiv) Last edited by guddu; March 17th, 2009 at 12:01 PM. Reason: Post your html code also here so that can run at my end. |
|
#7
| ||||
| ||||
| hi i tried your above code.i m not getting any syntax error.may be other part of code has problem.can u post your html code.(code which is calling this javascript functions) |
|
#9
| |||
| |||
| hi, can you post here your asp code that's calling the function from your .js file? thanks.... |
|
#10
| ||||
| ||||
| .JS files can include only script, nothing more nothing less. having HTML inside .JS files is not possible. when you have this: Code: <script type="text/javascript" src="showhide1.js"></script> for example, <B> is not valid JavaScript command. to include HTML contents you must use <iframe> tags, or server side code. Edit: sorry, noticed just now it's old thread... anyway, the information above might still be helpful for others. |
| The Following 2 Users Say Thank You to Shadow Wizard For This Useful Post: | ||
jmurrayhead (July 28th, 2009), micky (July 28th, 2009) | ||
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |