Page 1 of 1
my first js function
Posted: Thu Apr 07, 2011 6:54 am
by Isaac
weee! Using a tutorial and some transferable Python knowledge I wrote my first function. Fun!
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Isaac's site</title>
</head>
<script type="text/javascript">
var x = 0;
function myloop() {
for ( var x = 0; x <= 100; x++) {
document.write(x%11);
if (x%11==10) {
document.write("<p></p>");
}
}
}
</script>
<body>
<form><input type="button" onclick="myloop()" value="Mybutton"> </form>
</body>
</html>
Re: my first js function
Posted: Thu Apr 07, 2011 10:17 am
by fliptw
so it writes the remainder of a number divided by eleven, and if said remainder is 10, it prints a closed paragraph.
use the DOM luke....
Re: my first js function
Posted: Thu Apr 07, 2011 11:53 am
by Isaac
I'll get there eventually. I'm taking my time. I'm also able to do all my coding and testing within eclipse, which I really like. I need to figure out how to emulate my apache server so I don't have to test that code directly on the server. Then I could start writing and testing applications that stream data between the browser and server, which is cool.
Re: my first js function
Posted: Thu Apr 07, 2011 2:01 pm
by fliptw
run a local copy of apache on your machine.
Re: my first js function
Posted: Thu Apr 07, 2011 3:40 pm
by Isaac
It might come to that, but I'm a wimp. The eclipse might have an internal plugin that could work with it's "local server" it's been using to test my js & html stuff.
I have not yet googled anything on this, because I'm still becoming friends with Javascript. After I am, I'll start working on blending server-side CGI with browser-side Javascript. At least that's the current plan.
edit:
Again, I'm going to learn Javascript before I push to blending it with Python. But here's a diagram with what I have in mind:
- Diagram1.png (17.87 KiB) Viewed 1816 times
Made with Dia, the open source diagram application.
Re: my first js function
Posted: Thu Apr 07, 2011 7:19 pm
by Jeff250
Yeah, document.write() is icky. Remember, jQuery is your friend.
There are at least two ways in which server-side python and client-side Javascript can interact. One is that python can write Javascript in a metaprogramming sense. Another is that Javascript can query server-side python via AJAX.