|
Hi! For a project, i created a HTML page using JS.
function schreiben()
{
var htmlText="";
...
...
htmlText +=' <td height="15" bgcolor="#cccccc"><p><img class = "tast" id="taste19" src="images/ButtonPull.gif" width="15" height="15" border="0" onmousedown="press(19)" onmouseup="unpress(19)"></p></td>'
...
...
document.open();
document.write(htmlText);
document.close();
}
Now, in the same JS,i have the functions press and unpress
function press(index){
document.getElementById("taste"+index).src = taste_down;
}
In the beginning of the project, the HTML code was separate and it worked fine. I know its the document.getById... stuff that messing it up. Is there an alternative to call this function with the value?(taste is a pushbutton.)
thanks in advance, Messer
|
|
|
From your title, I first assumed perhaps you had an issue with cross-window javascript--that is, calling javascript in one window that affects objects in another window. After reading your post, that does not seem to be the case.
I don't understand what you are trying to do, nor how the window and HTML being generated by javascript has anything to do with your issue.
You say "taste is a pushbutton". Are you using an image button like this?
<INPUT TYPE="IMAGE" SRC="/forum/signup.gif">
Or is taste just an image?
Clarify a little, and I'll do what I can to help.
|
|
|
|
|
"Taste" is an imagebutton.
What im trying to do is to integrate a HTML page with an associated JS file.
First, i had an HTML page which called a javascript file containing the functions.
So,"taste" was in HTML and "press" and "unpress" were in the .js file.
Now i´m trying to pack everything in one file which is in JS.
So, i´m starting a .js file which generates a HTML page,which then in turn calls the functions contained in the .js file if the buttons are pressed.Stupid, but has to be ONE file in the end.
When i had two seperate Files it worked.
|
|
|
I'm still not certain what you want to do, so let me show examples, and you tell me if I'm on the right track.
You had a javascript file: myjsfile.js
function press() {
}
function unpress() {
} |
|
You had an HTML file in which you included the javascript file: myhtmlfile.htm
<html>
<head>
<script language=javascript src="/forum/myjsfile.js" type=text/javascript>
</script>
</head>
<body>
Here is my form with image buttons.
<form>
<INPUT TYPE="IMAGE" SRC="/forum/signup.gif">
</form>
</body>
</html> |
|
You were able to have your javascript functions interact with the buttons in the form. - this worked.
Now, instead of a static HTML page with included javascript, you want javascript to write out the HTML. If I have this correct....
Whether you include the javascript or had it inline with the HTML page, it would not make any difference. So we can forget that part of the equation. If you had a page that had your javascript functions and this javascript also wrote out your HTML form to the page, it would work fine as well -- as long as you wrote out the HTML to the same page.
If your javascript writes out the html to a NEW window, then you need to do one of 2 things. The simplest is probably to also write your press and unpress javascript functions to that window as well. That is, have your javascript write javascript and html to the window.
The other thing you could do is code things to work across windows. For example, if your parent window had the 2 functions plus created the new window with your form, then this second window becomes a "child" of the "parent".
<INPUT TYPE="IMAGE" SRC="/forum/signup.gif" onclick="parent.press(this);">
or
<INPUT TYPE="IMAGE" SRC="/forum/signup.gif" onclick="self.opener.press(this);">
Notice how the onclick event expects the javascript functions to be in the parent window rather than in it's own window.
I hope I've helped, if not, be patient and help me again to understand the issue.
|
|
|
|
|
I think the problem is with the
document.getElementById("taste"+index).src = taste_down;
in the functions.
i now have one HTML page which calls the function schreiben() in the JS file:
<HTML>
<HEAD>
<TITLE>Startseite</TITLE>
<script language="JavaScript" SRC="/forum/WPS.js"></SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<FORM>
<CENTER><INPUT TYPE=button NAME=Tabelle VALUE="Start SPS" onclick="schreiben()"></CENTER>
</FORM>
</BODY>
</HTML>
With schreiben(), i generate the HTML-Code in the first page.So, schreiben() contains all the HTML Code i need in one string variable and writes it using document.open();
document.write(htmlText);
document.close();
the "taste" is inside the string variable, might that be an issue?
Also in my JS file, there are the functions press and unpress.
If i used document.getElementById right, it searches in the HTML page which called the script?
that seems to be the problem.
I don´t want to paste all the code here since it is longish.
|
|
|
Maybe it's me, but I cannot make heads or tails of what you are trying to do. I don't want to see your whole code either. Can you create a small set of code examples to display exactly what you are trying to do? If you can describe the situation so I can understand it, I'm confident I can help you.
|
|
|
|
|
Maybe it's me, but I cannot make heads or tails of what you are trying to do |
|
Me neither :-)
What i´m trying to do is to create a JS which generates
the HTML page to be displayed. This goes on an embedded Server along with a tiny little HTML page to call the JS.
This way, only the generated HTML Code is accessible,sort of like with PHP which doesn´t work on this Server.
so, in the JS file is:
function press(index){
document.getElementById("taste"+index).src=taste_down;
}
function unpress(index){
var Stelle= BelegungsArray[index]
var value = document.applets["hebe"].readItem(Stelle);
switch(value){
case "0":
document.applets["hebe"].writeItem(Stelle,1);
[u]
document.getElementById("taste"+index).src = taste_on;[/u]
break;
}
}
function schreiben()
{
var htmlText="";
htmlText +='<p><img class = "tast" id="taste16" src="images/ButtonPull.gif" width="15" height="15" border="0" onmousedown="press(16)" onmouseup="unpress(16)"></p></td>'
...
...
document.open();
document.write(htmlText);
document.close();
}
the generation of HTML code works, a page is displayed, but the buttons don´t work
|
|
|
Maybe it's me, but I cannot make heads or tails of what you are trying to do |
|
Me neither :-)
What i´m trying to do is to create a JS which generates
the HTML page to be displayed. This goes on an embedded Server along with a tiny little HTML page to call the JS.
This way, only the generated HTML Code is accessible,sort of like with PHP which doesn´t work on this Server.
so, in the JS file is:
function press(index){
document.getElementById("taste"+index).src=taste_down;
}
function unpress(index){
var Stelle= BelegungsArray[index]
var value = document.applets["hebe"].readItem(Stelle);
switch(value){
case "0":
document.applets["hebe"].writeItem(Stelle,1);
[u]
document.getElementById("taste"+index).src = taste_on;[/u]
break;
}
}
function schreiben()
{
var htmlText="";
htmlText +='<p><img class = "tast" id="taste16" src="images/ButtonPull.gif" width="15" height="15" border="0" onmousedown="press(16)" onmouseup="unpress(16)"></p></td>'
...
...
document.open();
document.write(htmlText);
document.close();
}
the generation of HTML code works, a page is displayed, but the buttons don´t work
|
|
|
Maybe it's me, but I cannot make heads or tails of what you are trying to do |
|
Me neither :-)
What i´m trying to do is to create a JS which generates
the HTML page to be displayed. This goes on an embedded Server along with a tiny little HTML page to call the JS.
This way, only the generated HTML Code is accessible,sort of like with PHP which doesn´t work on this Server.
so, in the JS file is:
function press(index){
document.getElementById("taste"+index).src=taste_down;
}
function unpress(index){
var Stelle= BelegungsArray[index]
var value = document.applets["hebe"].readItem(Stelle);
switch(value){
case "0":
document.applets["hebe"].writeItem(Stelle,1);
[u]
document.getElementById("taste"+index).src = taste_on;[/u]
break;
}
}
function schreiben()
{
var htmlText="";
htmlText +='<p><img class = "tast" id="taste16" src="images/ButtonPull.gif" width="15" height="15" border="0" onmousedown="press(16)" onmouseup="unpress(16)"></p></td>'
...
...
document.open();
document.write(htmlText);
document.close();
}
the generation of HTML code works, a page is displayed, but the buttons don´t work
|
|
|
|
|
|
|
|