[thelist] CGI Form Submit in Javascript
TRG
java_fella at yahoo.com
Wed Dec 19 11:02:27 CST 2001
***It's a long one...sorry...***
I need to be able to convert this form (I've edited
some of the fields for content reasons) , which uses
the following two scripts (one to validate, one for
the submit), and have it POST the results as a Query
String which I can pass along to another URL designed
to handle the results.
Let's say the url is:
http://www.whereever.com/Engine.asp?
The text input fields in HTML are collected mostly
like this:
11.zip
4.firstname
5.lastname
and so on...the FORM action is...
<form name="tshirt" onSubmit="return
submit_form(tshirt);"
action="/cgi-bin/ipoform_engine.cgi" method="post">
<input type="hidden" name="config" value="tshirt">
<input type="hidden" name="1.code" value="$key">
<input type="text" size="22" class="iform"
style="width: 195px" name="UniqueCust">
<input type="text" size="22" class="iform"
style="width: 195px" name="first_name">
<input type="text" size="22" class="iform"
style="width: 195px" name="last_name">
and so on...
Which I need to do as a JavaScript submit and not
CGI..?? would I just specify the action to be
action="http://www.whereever.com/Engine.asp?"
What if I collected all of the data into an
associative array how would I load into the action
when it submits...???
If anyone has any thoughts or help...I'll repay the
favor in kind.
Thanks!
-Tom
http://www.templatekit.com
Here's the script:
<script language="JavaScript">
<!--
function submit_form(thisform) {
var not_filled;
var num_not_filled;
num_not_filled=0;
not_filled="";
all_required=true;
if (!thisform[3].value) {all_required=false;
not_filled=not_filled + 'E-mail Address, ';
++num_not_filled;}
if (!thisform[4].value) {all_required=false;
not_filled=not_filled + 'First Name, ';
++num_not_filled;}
if (!thisform[5].value) {all_required=false;
not_filled=not_filled + 'Last Name, ';
++num_not_filled;}
if (!all_required){
not_filled=not_filled.substring(0,
not_filled.length-2)
alert('The following information is required, but was
not entered: ' + not_filled + '.');
return(false);
}
if (!isEmail(thisform[3].value)) {
alert('A valid E-mail address is required to register
for this promotion.');
return(false);
}
answered = true;
checked=false;
if (thisform[2].checked) {checked=true;}
if (!checked) {answered = false;}
if (!answered) {
alert("You must agree to give us permission in order
to register for this promotion.");
return(false);
}
}
function isEmail(str) {
// are regular expressions supported?
var supported = 0;
if (window.RegExp) {
var tempStr = "a";
var tempReg = new RegExp(tempStr);
if (tempReg.test(tempStr)) supported = 1;
}
if (!supported)
return (str.indexOf(".") > 2) && (str.indexOf("@") >
0);
var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
var r2 = new
RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
return (!r1.test(str) && r2.test(str));
}
//-->
</script>
Any thoughts?
__________________________________________________
Do You Yahoo!?
Check out Yahoo! Shopping and Yahoo! Auctions for all of
your unique holiday gifts! Buy at http://shopping.yahoo.com
or bid at http://auctions.yahoo.com
More information about the thelist
mailing list