Forum Moderators: open

Message Too Old, No Replies

Calling a cgi function from Javascript

         

potato95

12:12 pm on May 9, 2005 (gmt 0)

10+ Year Member



I am sure there is a simple answer to this but I can't seem to get things to work....

I have a form that submits an email address to the server via the submit button however I want to use the "onSubmit" JS event to send the form data to another cgi script first via my "notify(aForm)" function.

Here is the function....

<script type="text/javascript" language="javascript" charset="iso-8859-1">
<!--
function notify(subscribeForm){
if(subscribeForm.email.value!="")
{alert("Thank you you will be emailed a Voucher code shortly.");
src="http://www2.mydomain.co.uk/cgi-bin/notify.cgi?email=subscribeForm.email.value";
return true;
}
alert("Need to enter an email address");
return false;
}

//-->
</script>

and the form on the page.....
<form method="get" id="subscribeForm" name="subscribeForm" onSubmit="return notify(this)" action="/cgi-bin/viewMailingListPage">Your email address:
<INPUT NAME=email TYPE=TEXT><input type=hidden value="3" name="site"><BR>
<INPUT VALUE="Subscribe to Mailing List" CLASS=subscribeButton NAME=subyes TYPE=SUBMIT></form>

I can't seem to get the "notify.cgi" script to work. If I type "http://www2.mydomain.co.uk/cgi-bin/notify.cgi?email=aValue" directly into the browser then all works fine so I don't think it is a problem with the serverside but the my javascript does not seem to fire the cgi script when embeded into the function.

Where am i going wrong?
Thanks.

rocknbil

6:20 pm on May 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What is "src" for in the context fo this bit of code?
if(subscribeForm.email.value!="")
{alert("Thank you you will be emailed a Voucher code shortly.");
src="http://www2.mydomain.co.uk/cgi-bin/notify.cgi?email=subscribeForm.email.value";
return true;
}

At any rate, it seems like you've got a good grip on perl, you're using two scripts, a more elegant (and easier!) solution might be to send the data to the notify script from your viewMailingListPage script, not from this page.

$result = curl `http://www2.mydomain.co.uk/cgi-bin/notify.cgi?email=$qs{'email'}`;

You could then use the value in $result to make sure it receved it ok.