Can html perform interactively or make decisions?

S

senhortomas

This is a link to some language translation flash cards I would like to
emulate:

http://www.quia.com/jfc/110270.html

Evidently some calculations or decisions are taking place. The cards
are randomized and counted. Where does the actual calculation software
reside? On the host computer? Although I have copied this web site
off-line to my hard drive, I have not been successful with displaying
the actual flash cards. What software tools other than html would I
need? Thnk you.
 
H

hywel.jenkins

This is a link to some language translation flash cards I would like to
emulate:

http://www.quia.com/jfc/110270.html

Evidently some calculations or decisions are taking place. The cards
are randomized and counted. Where does the actual calculation software
reside? On the host computer?

The example you've given uses Java, client-side.

Although I have copied this web site
off-line to my hard drive, I have not been successful with displaying
the actual flash cards. What software tools other than html would I
need?

JavaScript could do it, so could VBScript, so could Flash, so could
[insert server-side language here].
 
T

Toby Inkster

senhortomas said:
Can html perform interactively or make decisions?

No -- you'd need either a server-side or client-side programming language.

ECMAScript (a.k.a. Javascript) is really the only client-side scripting
language in town. Here's an example of something you could do with it:

<script type="text/javascript">
function sum ()
{
var A = document.getElementById('a');
var B = document.getElementById('b');
var C = document.getElementById('c');
C.value = A.value + B.value;
}
</script>
<div>
<input id="a"> +
<input id="b">
<input type="button" onclick="sum();" value="=">
<input id="c">
</div>

Server-side languages are more reliable in that they don't rely on browser
support -- the server does the hard work. The draw-back is that for
the browser has to load a new page to get the results, so to the end user,
the experience is slower.

You can potentially use any programming language that you like for
server-side scripts -- you just need to make sure your server is able to
run programmes in that language. Common choices are Perl, PHP, VBScript,
JScript, Java and Python, though C, C++, Shell, Fortran et al can be used
equally well.

Here is an example that performs a similar function to the script above,
but written in PHP:

<?php
$A = $_GET['a'];
$B = $_GET['b'];
if (isset($A) && isset($B))
$C = $A + $B;
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="GET">
<div>
<input name="a" value="<?=$A?>"> +
<input name="b" value="<?=$B?>">
<input type="submit" value="=">
<input name="c" value="<?=$C?>">
</div>
</form>

By combining client- and server-side programming, you can have the best of
both worlds: near-instantaneous results (thanks to client-side), with a
reliable fall-back.

Example:

<?php
$A = $_GET['a'];
$B = $_GET['b'];
if (isset($A) && isset($B))
$C = $A + $B;
?>
<script type="text/javascript">
function sum ()
{
// If this browser doesn't support
// getElementById, then fall back to
// PHP.
if (!document.getElementById)
return true;

// Add the numbers up and display
// the result.
var A = document.getElementById('a');
var B = document.getElementById('b');
var C = document.getElementById('c');
C.value = A.value + B.value;

// Cancel the PHP script.
return false;
}
</script>
<form onsubmit="return sum();"
action="<?=$_SERVER['PHP_SELF']?>"
method="GET">
<div>
<input id="a" name="a" value="<?=$A?>"> +
<input id="b" name="b" value="<?=$B?>">
<input type="submit" value="=">
<input id="c" name="c" value="<?=$C?>">
</div>
</form>

(Note: the scripts above are a little simplistic. In real life you'd
probably want to check that A and B are actual numbers before trying to
add them together. Adding "12" to "x" will result in "12x" in Javascript,
but "12" in PHP!)
 
D

David Graham

Toby Inkster said:
No -- you'd need either a server-side or client-side programming language.

ECMAScript (a.k.a. Javascript) is really the only client-side scripting
language in town. Here's an example of something you could do with it:

<script type="text/javascript">
function sum ()
{
var A = document.getElementById('a');
var B = document.getElementById('b');
var C = document.getElementById('c');
C.value = A.value + B.value;
}
</script>
<div>
<input id="a"> +
<input id="b">
<input type="button" onclick="sum();" value="=">
<input id="c">
</div>
Hi Toby
I just ran the javascript you posted to see it work. When I put in 4 + 3 I
get an answer of 43 - is that what you intended?
bye
David
 
T

Travis Newbury

The example you've given uses Java, client-side.
JavaScript could do it, so could VBScript, so could Flash, so could
[insert server-side language here].

Actually to "duplicate" that page you can not use server side
scripting. Key word being "duplicate" you can make something that
functions equally as well (or better as it would function on more
visitors computers)

Yes, that is nit-picking.
 
T

Toby Inkster

David said:
I just ran the javascript you posted to see it work. When I put in 4 + 3 I
get an answer of 43 - is that what you intended?

Not really -- posted without testing.

You can use the parseInt() function to convert from a string to an integer.

e.g.
var A = parseInt(document.getElementById('a'));
 
H

hywel.jenkins

Travis said:
The example you've given uses Java, client-side.
JavaScript could do it, so could VBScript, so could Flash, so could
[insert server-side language here].

Actually to "duplicate" that page you can not use server side
scripting. Key word being "duplicate" you can make something that
functions equally as well (or better as it would function on more
visitors computers)

You, you're saying that clicking the image couldn't fire a function
that uses the xmlHTTPRequest to go and get another image, then updates
the on that's currently on the screen? That would involve server-side
scripting.
 
D

David Graham

Toby Inkster said:
Not really -- posted without testing.

You can use the parseInt() function to convert from a string to an integer.

e.g.
var A = parseInt(document.getElementById('a'));
Hi Toby
I altered your code to take into account what you just posted, so it looks
like this now:
<script type="text/javascript">
function sum ()
{
//var A = document.getElementById('a');
var A = parseInt(document.getElementById('a'));
//var B = document.getElementById('b');
var B = parseInt(document.getElementById('b'));
//var C = document.getElementById('c');
var C = parseInt(document.getElementById('c'));
C.value = A.value + B.value;
}
</script>
</HEAD>

<BODY>
<div>
<input id="a"> +
<input id="b">
<input type="button" onclick="sum();" value="=">
<input id="c">
</div>

When you click the button now nothing happens - no value for C appears on
the screen!
Any obvious mistake in my interpretation of your last post please?
bye
David
 
T

Travis Newbury

Travis said:
The example you've given uses Java, client-side.
JavaScript could do it, so could VBScript, so could Flash, so could
[insert server-side language here].
Actually to "duplicate" that page you can not use server side
scripting. Key word being "duplicate" you can make something that
functions equally as well (or better as it would function on more
visitors computers)
You, you're saying that clicking the image couldn't fire a function
that uses the xmlHTTPRequest to go and get another image, then updates
the on that's currently on the screen? That would involve server-side
scripting.

Show me a page doing that without and client scripting and I will say
"good job hywel"
 
H

hywel.jenkins

Travis said:
Travis said:
The example you've given uses Java, client-side.
JavaScript could do it, so could VBScript, so could Flash, so could
[insert server-side language here].
Actually to "duplicate" that page you can not use server side
scripting. Key word being "duplicate" you can make something that
functions equally as well (or better as it would function on more
visitors computers)
You, you're saying that clicking the image couldn't fire a function
that uses the xmlHTTPRequest to go and get another image, then updates
the on that's currently on the screen? That would involve server-side
scripting.

Show me a page doing that without and client scripting and I will say
"good job hywel"

I didn't say it can't be done *without* client-side scripting. *You*
said it *cannot* be done using server-side scripting.
 
T

Toby Inkster

David said:
function sum ()
{
//var A = document.getElementById('a');
var A = parseInt(document.getElementById('a'));
//var B = document.getElementById('b');
var B = parseInt(document.getElementById('b'));
//var C = document.getElementById('c');
var C = parseInt(document.getElementById('c'));
C.value = A.value + B.value;
}

function sum ()
{
var A = parseInt(document.getElementById('a').value);
var B = parseInt(document.getElementById('b').value);
document.getElementById('c').value = A + B;
}
 
T

trippy

Travis Newbury took the hamburger, threw it on the grill, and I said "Oh
wow"...
Travis said:
The example you've given uses Java, client-side.
JavaScript could do it, so could VBScript, so could Flash, so could
[insert server-side language here].
Actually to "duplicate" that page you can not use server side
scripting. Key word being "duplicate" you can make something that
functions equally as well (or better as it would function on more
visitors computers)
You, you're saying that clicking the image couldn't fire a function
that uses the xmlHTTPRequest to go and get another image, then updates
the on that's currently on the screen? That would involve server-side
scripting.

Show me a page doing that without and client scripting and I will say
"good job hywel"

http://www.runescape.com

Well, you'll need one HttpServletRequest for the servlet.

(.jsp pages get translated to servlets)

Once you're actually in the doGet/doPost method, you won't need one at
all. Runescape doesn't require you to refresh the page everytime you
move or fight something, nor does any other game site that uses an
applet. In fact, if you hit refresh, you're logged off of the game
(Runescape) and you have to log in again.

AFAICT, about the only thing you have to do client side is make sure
people can find a session again. And have a page.

Guild Wars would be the only totally client-side game I can think of.
You actually get all the files you need, as opposed to going to some
site to play on it. It's ok. Kinda fun actually but it's kinda buggy. I
don't know if being all client side has anything to do with that.

--
trippy
mhm31x9 Smeeter#29 WSD#30
sTaRShInE_mOOnBeAm aT HoTmAil dOt CoM

NP: "He-Man Woman Hater" -- Extreme

"Now, technology's getting better all the time and that's fine,
but most of the time all you need is a stick of gum, a pocketknife,
and a smile."

-- Robert Redford "Spy Game"
 
T

Travis Newbury

Hywel said:
Good come-back. Admit it - you were being a smart arse and got it
wrong.

Let's read what we both said.....

you said:
The example you've given uses Java, client-side.
JavaScript could do it, so could VBScript, so could Flash, so could
[insert server-side language here].

You imply that each of these can do it by themselves. That is the
"could do it, so could" part.

I replied
Actually to "duplicate" that page you can not use server side
scripting. Key word being "duplicate" you can make something that
functions equally as well (or better as it would function on more
visitors computers)

This also implys "by it self. Which you agree. Server side scripting
can not duplicate this by itself. I even stated that if you used only
server side script and made something with similar functionallity it
would actually work on more visitors computers.

So learn to READ before you make an ass of yourself. My "What ever"
comment was to save you from looking like an ass, but you couldn't let
it go, and now you look like an ass.
 
D

David Graham

Toby Inkster said:
function sum ()
{
var A = parseInt(document.getElementById('a').value);
var B = parseInt(document.getElementById('b').value);
document.getElementById('c').value = A + B;
}
Thanks very much Toby
bye
david
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top