Carlitos
11-19-2002, 09:42 PM
Apologies for the basic level of this question. I am using a javascript that forces the user to rank order responses on a survey form.
However I am not clear on syntax. The java script itself is at the bottom of this message. Within it, I assume that I need to change:
document.clear();
document.write("success! it be sweet
\n");
to submit();or document.form.submit(); in order allow the form to post to a cgi script, but am not sure of this syntax to use. Am I even close to being on the right track with this change?
Also, am I not sure if I would need to change the HTML form tag in any way:
<FORM ACTION="../cgi-bin/survey.cgi" METHOD="POST">
Thanks for any and all help. Here is the script:
<SCRIPT LANGUAGE="JavaScript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Original: Kent Rauch (kent@restekcorp.com) -->
<!-- Web Site: http://www.restekcorp.com -->
<!-- Begin
function validator() {
// copyright 2002 Kent Rauch
// global declaration
badrank = false;
rankem(1,4);
rankem(2,5);
if (!badrank) {
// this is a "phony submit" for testing purposes
document.clear();
document.write("success! it be sweet<br>\n");
}
}
// ---------------------------------------------------------
// Validate ranking questions: each value used exactly once.
function rankem(question, q_size) {
// copyright 2002 Kent Rauch
var aLert1 = "";
var aLert2 = "";
// supports up to 26 items to be ranked -- extend this array to increase
var cal = "a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z";
cal = cal.split('.');
var a = 0;
var irate = "rink" + question;
eval(irate + " = new Object();");
var myrate = "";
for (var x = 0; x < q_size; ++x) {
myrate = "q"+question+cal[x];
eval(irate + "[" + x + "] = document.test_form." + myrate + ".selectedIndex");
if (eval(irate + "[" + x + "]")) {
++a;
for (var y = 0; y < x; ++y) {
if (eval(irate + "[" + y + "]") == eval(irate + "[" + x + "]")) {
aLert1 = "Question "+ question +": please use each ranking only once.\n";
}
}
}
}
if (a != q_size) {
aLert2 = "Question " + question +":please rank all items.\n";
}
var aLert = aLert1 + aLert2;
if (aLert) {
alert(aLert);
badrank = true;
}
}
// End -->
</script>
However I am not clear on syntax. The java script itself is at the bottom of this message. Within it, I assume that I need to change:
document.clear();
document.write("success! it be sweet
\n");
to submit();or document.form.submit(); in order allow the form to post to a cgi script, but am not sure of this syntax to use. Am I even close to being on the right track with this change?
Also, am I not sure if I would need to change the HTML form tag in any way:
<FORM ACTION="../cgi-bin/survey.cgi" METHOD="POST">
Thanks for any and all help. Here is the script:
<SCRIPT LANGUAGE="JavaScript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Original: Kent Rauch (kent@restekcorp.com) -->
<!-- Web Site: http://www.restekcorp.com -->
<!-- Begin
function validator() {
// copyright 2002 Kent Rauch
// global declaration
badrank = false;
rankem(1,4);
rankem(2,5);
if (!badrank) {
// this is a "phony submit" for testing purposes
document.clear();
document.write("success! it be sweet<br>\n");
}
}
// ---------------------------------------------------------
// Validate ranking questions: each value used exactly once.
function rankem(question, q_size) {
// copyright 2002 Kent Rauch
var aLert1 = "";
var aLert2 = "";
// supports up to 26 items to be ranked -- extend this array to increase
var cal = "a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z";
cal = cal.split('.');
var a = 0;
var irate = "rink" + question;
eval(irate + " = new Object();");
var myrate = "";
for (var x = 0; x < q_size; ++x) {
myrate = "q"+question+cal[x];
eval(irate + "[" + x + "] = document.test_form." + myrate + ".selectedIndex");
if (eval(irate + "[" + x + "]")) {
++a;
for (var y = 0; y < x; ++y) {
if (eval(irate + "[" + y + "]") == eval(irate + "[" + x + "]")) {
aLert1 = "Question "+ question +": please use each ranking only once.\n";
}
}
}
}
if (a != q_size) {
aLert2 = "Question " + question +":please rank all items.\n";
}
var aLert = aLert1 + aLert2;
if (aLert) {
alert(aLert);
badrank = true;
}
}
// End -->
</script>