Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-07-2010, 06:16 PM   PM User | #1
Nexusfactor
New to the CF scene

 
Join Date: Dec 2010
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Nexusfactor is on a distinguished road
Redirect and Submit Button

Hello

Wondering something, I created a form and have I have it submit when the user clicks the Submit button.



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Assignment 4</title>
<style type="text/css">
</style>
</head>

<body style="color: #009999; background-color: #000000">

<form action="mailto:whatisthematrix01@hotmail.com" name="frmCustomer" method="post">

<table style="width: 85%; height: 222px;">
<tr>
<td>
<img alt="Space Ship" height="223" src="spaceship_cg2.jpg" style="float: left" width="761" /></td>
</tr>
</table>

<p>&nbsp;</p>
<table style="width: 100%">
<tr>
<td class="style1">Interstellar Shipping - Customer Registration </td>
</tr>
</table>
<p>&nbsp;</p>

<table class="style2">
<tr>
<td class="style3">
First Name:</td>
<td colspan="2" style="width: 273px">
<input id="Text1" type="text" name="Fname" /></td>
</tr>
<tr>
<td class="style3">
Last Name</td>
<td colspan="2" style="width: 273px">
<input id="Text2" type="text" name="Lname" /></td>
</tr>
<tr>
<td class="style3">
City: </td>
<td colspan="2" style="width: 273px">
<input id="Text3" type="text" name="UseCity" /></td>
</tr>
<tr>
<td class="style3">
Country:</td>
<td colspan="2" style="width: 273px">
<input id="Text4" type="text" name="UserCountry" /></td>
</tr>
<tr>
<td class="style3">
E-Mail:</td>
<td colspan="2" style="width: 273px">
<input id="Text6" name="userEmail" type="text" /></td>
</tr>
<tr>
<td class="style3">
Username:</td>
<td colspan="2" style="width: 273px">
<input id="Text5" type="text" name="Username" /></td>
</tr>
<tr>
<td class="style3">
Password:</td>
<td colspan="2" style="width: 273px">
<input id="Password1" type="password" name="Userpassword" /></td>
</tr>
<tr>
<td class="style3" style="height: 35px">
Gender:</td>
<td style="width: 307px; height: 35px;">
Male
<input name="radGender" type="radio" value="radMale" /> Female
<input name="radGender" type="radio" value="radFemale" /></td>
<td style="width: 273px; height: 35px;">
</td>
</tr>
<tr>
<td class="style3">
<input id="Submit1" type="button" value="submit" onclick="doSave()"/></td>
<td colspan="2" style="width: 273px">
<input id="Reset1" type="reset" value="reset" /></td>
</tr>
</table>
</form>


<script Language = "JavaScript">



function ltrim(varIn)
{/*Purpose: Trims the leading spaces from a string*/
var varOut = ""

if(!varIn)
{
// string is null, so nothing to do
}
else // string has at least one character
{
for(intI=0; intI < varIn.length; intI++)
{
if(varIn.charAt(intI) != " ")
{
//first non-space char found so return
//string from this character forward
varOut = varIn.substring(intI)
break
}
}
}
return varOut
}

function doSave()
{

var fOk = true
var strSuperMessage
var superFirstName = document.frmCustomer.Fname
var superLastName = document.frmCustomer.Lname
var superUserCity = document.frmCustomer.UseCity
var superUserName = document.frmCustomer.Username
var superUserPassword = document.frmCustomer.Userpassword
var superUserEmail = document.frmCustomer.userEmail

var checkDigit = /\d/;

if ((ltrim(superFirstName.value)).length == 0)
{
fOk = false
strSuperMessage = "First Name Required"
superFirstName.focus()
}
else
{
if ((ltrim(superLastName.value)).length == 0)
{
fOk = false
strSuperMessage = "Last Name Required"
superLastName.focus()

}
else
{
if ((ltrim(superUserCity.value)).length == 0)
{
fOk = false
strSuperMessage = "City Required"
superUserCity.focus()
}

else
{
if ((ltrim(superUserName.value)).length == 0)
{
fOk = false
strSuperMessage = "Username Required"
superUserName.focus()


}


else
{
if ((ltrim(superUserEmail.value)).length == 0)
{
fOk = false
strSuperMessage = "E-Mail Required"
superUserEmail.focus()
}

else
{
if
(superUserEmail.value.indexOf("@") == -1
|| superUserEmail.value.indexOf(".")== -1)
{
fOk = false
strSuperMessage = "The entered e-mail address is not " +
"valid.\nE-mail addresses must " +
"be in the form name@domain."
superUserEmail.focus()
}
else
{

if (superUserPassword.value.search(checkDigit) ==-1)
{
fOk=false
strSuperMessage = "Please enter at least one digit in your password field.";
superUserPassword.focus()


}

else
{
if ((document.frmCustomer.radGender[0].checked==false) &&
(document.frmCustomer.radGender[1].checked==false))
{
fOk = false
strSuperMessage = "Gender Required"
}


}
}
}}}}}

if(fOk)
{
document.frmCustomer.submit();
//window.location="http://www.google.com"
}

else
alert(strSuperMessage)
}

</script>

</body>
</html>

Is it okay if I redirect to Google like I did here.

if(fOk)
{
document.frmCustomer.submit();
//window.location="http://www.google.com"
}

I can't do it in the form action, because I have the mailto link. Simply put, what I did in the if statement, is that okay, there would be no problem with it?

Last edited by Nexusfactor; 12-07-2010 at 06:41 PM..
Nexusfactor is offline   Reply With Quote
Old 12-07-2010, 06:46 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,098
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
You can only redirect after a form submit using server-side scripting. Javascript cannot do that.

The trouble with using mailto: to send form results is its unpredictability. The method it is highly dependent on the browser in use and the email client in use (some people have only Yahoo or Hotmail). In particular, your visitor must have Outlook or Outlook Express as the default client for this to work correctly. Even if your visitor is using Internet Explorer, but the default mail client is different (e.g. Eudora), your mailto form will not work. With all of the browser troubles, you're likely to lose about half of your users' messages. Most of the email clients that can successfully send a mail will prompt the user by a security dialog prior to sending - this can scare many users from continuing. Also, what about people with Javascript disabled?

If you are going to use a form then use a server-side formmail script as the action - there are several good free ones out there.


BTW, when posting here please follow the posting guidelines and wrap your code in CODE tags. This means use the octothorpe or # button on the toolbar. You can (and should) edit your previous post.


Lottery: A tax on people who are bad at math.

Last edited by Philip M; 12-07-2010 at 06:54 PM..
Philip M is offline   Reply With Quote
Old 12-07-2010, 08:28 PM   PM User | #3
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,055
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
Who is your webhost, and why can't you use PHP to process the form?

If you can't use PHP (or Perl) ... you can't process the form.
mlseim is offline   Reply With Quote
Old 12-08-2010, 01:39 AM   PM User | #4
Nexusfactor
New to the CF scene

 
Join Date: Dec 2010
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Nexusfactor is on a distinguished road
I am using my school's server, however, a little Google searching revealed that php and hotmail don't mix. However, this javascript page I was just wondering if it was okay to do the redirect where I did it.
Nexusfactor is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:20 AM.


Advertisement
Log in to turn off these ads.