View Full Version : AJAX advice anyone?

02-15-2008, 12:40 AM
I've made a simple mailing list form nested in a div layer floating in the corner of the screen. its basically just a text field and submit button. is it possible to hide the div layer that the form is in, when the user clicks submit?

here is the code for the form:

<!-- newsletter subscribe below here -->

<script language="Javascript" type="text/javascript">
var fieldstocheck = new Array();
fieldnames = new Array();
function checkform() {
for (i=0;i<fieldstocheck.length;i++) {
if (eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].value") == "") {
alert("Please enter your "+fieldnames[i]);
return false;
return true;
function addFieldToCheck(value,name) {
fieldstocheck[fieldstocheck.length] = value;
fieldnames[fieldnames.length] = name;

<form method="post" action="http://www.mydomain.com/lists/?p=subscribe&id=1" name="subscribeform">
Email:<input type="text" name="email" value = ""><br>
<script language="Javascript" type="text/javascript">addFieldToCheck("email","Email Address");</script>
Name: <input type="text" name="attribute2" value = "">
<script language="Javascript" type="text/javascript">addFieldToCheck("attribute2","Name");</script>
<input type="hidden" name="list[1]" value="signup" />
<input type="submit" name="subscribe" value="Subscribe" onClick="return checkform();">

<!-- newsletter subscribe ends here -->

02-15-2008, 05:47 PM
If you know JavaScript, you should try this AJAX tutorial (http://www.w3schools.com/ajax/default.asp). I did it myself yesterday, and it's not that hard. By the time you finish the tutorial, you should have an idea of what to do. In fact, it covers the submission of forms, which is what you need. (If you know JS, it should only take an hour or less to get through. If your rough on JS, it might take longer.)