How to know if javascript is executing?
There are several references on this forum to modifying a page's behavior by placing html of the following form in the body of a page:
Quote:
<script type="text/javascript">xr_v1(document.getElementById('message ').parentNode.parentNode)</script>
Although I've following the "instructions" for using it, I have seen no evidence that it actually works or is even executing ... which leads me to these questions:
Is there a statement I can add to that block that would display a message or change a color ... or something?
xr_v1 appears to be a function. Where might I find it documented?
When such a script is in the body html, when is it executed?
As you can tell, I'm not versed in javascript. And it's tough to get even a toehold when viewing resources like W3School. But I'm trying to learn.
Thanks in advance for any assistance.
Re: How to know if javascript is executing?
I normally follow siran or Acorn when it comes to JS Contours, I just dabble (badly).
However copy the following text, paste it into Notepad, save it as test.html & run it in a browser.
Quote:
<html>
<body>
<p id="p1">What's your name?</p>
<button type="button" onclick="myFunction()">Answer</button>
<p><p/>
<button type="button" onclick="myFunction2()">Reset</button>
<script>
function myFunction() {
document.getElementById("p1").innerHTML = "Contours";
document.getElementById("p1").style.color = "blue";
}
function myFunction2() {
document.getElementById("p1").innerHTML = "What's your name?";
document.getElementById("p1").style.color = "red";
}
</script>
</body>
</html>
Getting that to work in Xara isn't within my knowledge.
Re: How to know if javascript is executing?
@Egg: Thanks for that sequence. It's easy to follow what it does when opened in a browser. It's certainly a good start.
As a test, I named one of the page's text fields "text" and made a crude attempt at grafting one statement into the snippet in the page body ... without any result.
Quote:
<script type="text/javascript">xr_v1(document.getElementById('message ').parentNode.parentNode);document.getElementById( "text").style.color = "red"</script>
If it's even possible to do this, maybe someone can correct my syntax error(s).
I appreciate your help.
1 Attachment(s)
Re: How to know if javascript is executing?
Don't know how you attach the code to Xara Buttons but this works with html generated buttons.
Re: How to know if javascript is executing?
Yes, it does work as you've described. But when I attempted to adapt a single statement into a super-simple test case:
Quote:
<script>document.getElementById("text").style.colo r = "red"</script>
... nothing changed. I suspect I'm not in the right ballpark with the syntax.
Thanks for posting the example. I'll continue to look for other examples of "body html" to get a handle on uses.
Re: How to know if javascript is executing?
[QUOTE]<script>document.getElementById("text").style.co lo r = "red"</script>[/QUOTE
Try
document.getElementById("text").style.color = "red";
thats without the gap between the o and r in color and the semicolon on the end.
Re: How to know if javascript is executing?
Seems to me the original insert
that you have a space in 'colo r' maybe not picking that script up due to the space..
Jim
1 Attachment(s)
Re: How to know if javascript is executing?
@Scotty: those occasional blanks are inserted by the forum software ... to keep text strings from being too long to wrap, I believe.
@egg: I got the result shown below. In a way, it gives a hint as to how the body html is interpreted. I'm still at a loss of how to get it to tell the browser that I want a different result than what is defined in the xara-built html. Am I looking at this all wrong? If I am, how do scripts in the body html modify elements like slider widgets?
Thanks for the responses.
Attachment 114521
1 Attachment(s)
Re: How to know if javascript is executing?
I believe the space is down to a glitch in the forum quote Jim. I tried editing and it added more spaces.
Contours, try the attached.
1 Attachment(s)
Re: How to know if javascript is executing?
Contours, are you also naming the text block "HTMLBlockText" ?