Newsgroup: it.comp.lang.javascript
Titolo: make a script work without "<form action=>"

The encryption script bellow is working with an "form action="   .... i need
to make the script work without "form action="   .... i mean , the <INPUT
onclick="select_action(encipher)" type="submit" value="Encrypt"> needs to
work directely to the javascript without passing thru the "form action"
is it possible ?
____________________________________________________________________________
_______________________________________
-ORIGINAL SCRIPT-
->HTML>
->HEAD>
->TITLE>
->/TITLE>
->SCRIPT type=text/javascript>
var block=64, buffer=1024;
function b0f(c) { return c < 16 ? '0' + c.toString(16) : c.toString(16); }
function salt(s) { var n = 0;
for (var i=0; i<s.length; i++) n += i&s.charCodeAt(i);
return b0f(n%256); }
function encrypt(s,k) { if (s.length > block) {
var m=parseInt(s.length/block), t=Math.round(m/2)*block;
return encrypt(s.substr(0, t), k) + encrypt(s.substr(t), k);  }
var r=parseInt(Math.random()*256), o=b0f(r), i;
for (i=0; i<s.length; i++) {  o +=
b0f(s.charCodeAt(i)^r^k.charCodeAt(i%k.length)); }
return o; }
function encipher(f) { var s=f.FirstName.value, k=salt(f.Email.value), r=k,
b=buffer,  p=0, n=Math.floor(s.length/b)+1;
while (n > p++) {  self.status = 'Encrypting block ' + p + '/' + n; r +=
encrypt(s.substr((p-1)*b, b), f.Email.value); } f.FirstName.value = r;
self.status = 'Done'; }
->/SCRIPT>
->SCRIPT type=text/javascript>
function select_action(script_function) {
 if (typeof(script_function) == 'function')
  select_action.prototype.selected = script_function;
 else if (select_action.prototype.selected)
  select_action.prototype.selected(script_function);
}
->/SCRIPT>
->BODY>
->FORM name="cipher"  action="javascript:select_action(document.cipher)"
method="post">
->TABLE align=center>
KEY:
->INPUT maxLength=64 name="Email"> <BR>
->INPUT TYPE="text" NAME="FirstName" SIZE="50" maxlength="50">
->BR>
->BR>
->BR>
->BR>
->INPUT onclick="select_action(encipher)" type="submit" value="Encrypt">
->/TABLE>
->/FORM>
->/BODY>
->/HTML>
____________________________________________________________________________
__________________________________________
-MODIFIED SCRIPT TO SHOW WHAT I MEAN-
->HTML>
->HEAD>
->TITLE>
->/TITLE>
->SCRIPT type=text/javascript>
var block=64, buffer=1024;
function b0f(c) { return c < 16 ? '0' + c.toString(16) : c.toString(16); }
function salt(s) { var n = 0;
for (var i=0; i<s.length; i++) n += i&s.charCodeAt(i);
return b0f(n%256); }
function encrypt(s,k) { if (s.length > block) {
var m=parseInt(s.length/block), t=Math.round(m/2)*block;
return encrypt(s.substr(0, t), k) + encrypt(s.substr(t), k);  }
var r=parseInt(Math.random()*256), o=b0f(r), i;
for (i=0; i<s.length; i++) {  o +=
b0f(s.charCodeAt(i)^r^k.charCodeAt(i%k.length)); }
return o; }
function encipher(f) { var s=f.FirstName.value, k=salt(f.Email.value), r=k,
b=buffer,  p=0, n=Math.floor(s.length/b)+1;
while (n > p++) {  self.status = 'Encrypting block ' + p + '/' + n; r +=
encrypt(s.substr((p-1)*b, b), f.Email.value); } f.FirstName.value = r;
self.status = 'Done'; }
->/SCRIPT>
->BODY>
->FORM name="cipher">
->TABLE align=center>
KEY:
->INPUT maxLength=64 name="Email"> <BR>
->INPUT TYPE="text" NAME="FirstName" SIZE="50" maxlength="50">
->BR>
->BR>
->BR>
->BR>
->INPUT onclick="whatever" type="button" value="Encrypt">
->/TABLE>
->/FORM>
->/BODY>
->/HTML>
____________________________________________________________________________
__________________________________________

->INPUT onclick="select_action(encipher)" type="submit" value="Encrypt">
Stop posting to netscape.public.beta.feedback.javascript.  This is not
beta feedback!  Followups to comp.lang.javascript.
Instead of an ACTION attribute, include an onSubmit attribute that
performs your Javascript function and then always returns false.
Returning false will cancel the form submission.
<form name=cipher onSubmit="selection_action(document.cipher); return
false">
Regards,
Steve