...

View Full Version : Javascript form submits on same page



Brin
12-27-2006, 11:36 AM
Hi-

I have a small problem with the javascript part of a template to template adaptation... I have two forums, when they are submitted they are first checked by some javascript in the code. The problem is that they get mixed up. When I put data into the support form I get a no username error. When I put login info it sends it to support...

Never used javascript before, can just understand what Im looking at but I have no idea how to fix this problem.

I tried making a iframe but Ive never been a fan of them. Plus when I put in an iFram it messes with my sensitive template.

Any help appreciated :)


<script language=javascript>
function checklogin() {
if (document.loginform.username.value=='') {
alert("Please enter your username!");
document.loginform.username.focus();
return false;
}
if (document.loginform.password.value=='') {
alert("Please enter your password!");
document.loginform.password.focus();
return false;
}
return true;
}
</script>

<div id="title">
<form method=post name=loginform onsubmit="return checklogin()">
<input type=hidden name=a value='do_login'>
user<input type=text name=username class=inpts size=15>
pass<input type=password name=password class=inpts size=15>
<input type=submit value="Login" class=sbmt size=15>
</div>
<UL>
<div id="content1">

<h3>Support Form:</h3><br>


<script language=javascript>

function checkform() {
if (document.mainform.name.value == '') {
alert("Please type your full name!");
document.mainform.name.focus();
return false;
}
if (document.mainform.email.value == '') {
alert("Please enter your e-mail address!");
document.mainform.email.focus();
return false;
}
if (document.mainform.message.value == '') {
alert("Please type your message!");
document.mainform.message.focus();
return false;
}
return true;
}

</script>

<form method=post name=mainform onsubmit="return checkform()">
<input type=hidden name=a value=support>
<input type=hidden name=action value=send>

<table cellspacing=0 cellpadding=2 border=0>
<tr>
<td>Your Name:</td>
<td><input type="text" name="name" size=30 class=inpts></td>
</tr>
<tr>
<td>Your Email:</td>

<td><input type="text" name="email" size=30 class=inpts></td>
</tr>
<tr>
<td colspan=2>Message:<br><br><textarea name=message class=inpts cols=45 rows=4></textarea>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type=submit value="Send" class=sbmt></td>
</tr></table>
</form>

nikkiH
12-27-2006, 02:20 PM
Your html is rather invalid. :D
You should be quoting your attributes, too, just to be safe, even though I don't think it's technically required for the more forgiving doctypes. Also, be aware that if you aren't specifying a doctype, it defaults to quirks mode.

Your main issue is a missing </form> tag before the start of the next form.
You should really run this through a validator before trying to troubleshoot the script. Invalid html often messes up script, plus it's not as cross-browser. Internet Explorer is more forgiving than most browsers when it comes to invalid html.

Brin
12-27-2006, 07:37 PM
Invalid html... good one :D

Stuck in a form ending tag and works well on firefox & IE :thumbsup:

The reason for the html being rather sloppy is because I had to cut a template into many files so that it would work with a downloaded script. (There were around 10 files I had to edit :rolleyes:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum