Page 1 of 1

Form Scripting problem, help please!

Posted: Sat Jan 03, 2009 5:13 pm
by poehalcho
ok, this is the final part i need to have for my site.
i can't get it to check whether the form has been filled in or not...


Code:

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
</head>
<body> <script type="text/javascript">
function testform()
{
if(document.forms[0].elements[0].value==""
|| document.forms[0].elements[1].value=="none"
|| document.forms[0].elements[2].value==""
|| document.forms[0].elements[3].value==""
|| document.forms[0].elements[4].value=="")
  {
   alert("You must fill in all the information in this form")
   }
}
</SCRIPT>


<form>
<tr>
  <td>Please enter your Name</td><br>
  <td><input type="text" name="Name" size="50" maxlength="35" /></td>
</tr>
<br><br>
<tr>
  <td>What is your age?</td><br>
  <td>
   <select name="age">
    <option>none</option
    <option>5 </option>
    <option>6 </option>
    <option>7 </option>
    <option>8 </option>
    <option>9 </option>
   <option>10 </option>
    <option>11 </option>
   <option>12</option>
   <option>13</option>
   <option>14</option>
    <option>15 </option>
    <option>16 </option>
    <option>17 </option>
    <option>18 </option>
    <option>19 </option>
    <option>20 </option>
    <option>older than 20 </option>
    </select>
</td>
</tr>
<br><br>
<tr>
  <td valign="top">What is your favorite Character</td><br>
  <td>
   <input type="radio" name="character" value="Sonic" />Sonic
    <input type="radio" name="character" value="Knuckles" />Knuckles
    <input type="radio" name="character" value="Tails" />Tails
    <input type="radio" name="character" value="Shadow" />Shadow
    <input type="radio" name="character" value="Rouge" />Rouge
    <input type="radio" name="character" value="Eggman" />Eggman
    <input type="radio" name="character" value="Omega" />Omega
    <input type="radio" name="character" value="Metal" />Metal

  </td>
</tr>
<br><br>

<tr>
  <td valign="top">What are your favorite games?</td><br>
  <td>
   <input type="checkbox" name="game" value="Sonic 2D games" />Sonic 2D games<br />
   
    <input type="checkbox" name="game" value="Sonic Adventure 1" />Sonic Adventure 1<br />
    <input type="checkbox" name="game" value="Sonic Adventure 2" />Sonic Adventure 2<br />
      <input type="checkbox" name="game" value="Sonic Heroes" />Sonic Heroes<br />
      <input type="checkbox" name="game" value="Sonic the hedgehog 2006" />Sonic the hedgehog 2006<br />
      <input type="checkbox" name="game" value="Shadow the Hedgehog" />Shadow the Hedgehog<br />
    <input type="checkbox" name="game" value="Sonic and the Secret Rings" />Sonic and the Secret Rings<br />
      <input type="checkbox" name="game" value="Sonic Unleashed" />Sonic Unleashed<br />
</td>
</tr>
<br>
<tr>
  <td><button type="reset">Reset</button></td>
   
   
  <td><INPUT TYPE="button" VALUE="send e-mail" onClick="self.location='mailto:SonicDX_Adventure@Hotmail.com';"></td>
   

   
   
   <form action=mailto:Sonicdx_adventure@hotmail.com method="Email" name="form"></script>
</tr>

</form>
</body>
</html>




if anyone can help, it is greatly appreciated, with this done i can finally rest a bit T__T

edit:
i got the basics fro this site
http://www.geocities.com/sunsetstrip/al ... .htm#sec23

Re: Form Scripting problem, help please!

Posted: Sat Jan 03, 2009 5:29 pm
by klokus
you must link your submit-button with your "check"-function (testform())

Re: Form Scripting problem, help please!

Posted: Sat Jan 03, 2009 5:36 pm
by poehalcho
mind explaining how?

Re: Form Scripting problem, help please!

Posted: Sat Jan 03, 2009 5:40 pm
by klokus
I'm not really familiar with your language, but I can see that you didn't use your function (above) in the source from the onClick-event (button) (could also be the formaction thingy)

Re: Form Scripting problem, help please!

Posted: Sat Jan 03, 2009 5:50 pm
by NuclearSilo
in function testform, add:

Code: Select all

else self.location='mailto:SonicDX_Adventure@Hotmail.com';


at the bottom:

Code: Select all

<td><INPUT TYPE="button" VALUE="send e-mail" onClick="testform();"></td>


there is an error, you open with a form and close with a script tag:

Code: Select all

<form action=mailto:Sonicdx_adventure@hotmail.com method="Email" name="form"></script>


All inputs should be put in form. The code above should be put at the top where starts the first form

The send button should be input type submit (if you want to send the data to other page, otherwise you don't need form tag)

forms[0] and elements[0] can be replaced by their name or id to easier to keep track:

Code: Select all

document.form.Name.value==""

Re: Form Scripting problem, help please!

Posted: Sat Jan 03, 2009 8:23 pm
by poehalcho
well I got somewhere with the help of Vandango, but he's playing medieval now...

currently it notices everything. but when you make it submit it looks for page named after my email. help please...

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
</head>
<body>
<script type="text/javascript">
function disp_alert()

{

if (form.name.value == "")
   
   {
          alert( "Please enter your name." );
            form.action = "form.htm"
   }

}


</script>
<form name="form" action="Sonicdx_adventure@hotmail.com" method="post" onsubmit ="return disp_alert();">
<tr>
  <td>Please enter your Name</td><br>
  <td><input type="text" name="name" size="50" maxlength="35" /></td>
</tr>
<br><br>
<tr>
  <td>What is your age?</td><br>
  <td>
   <select name="age">
    <option>5 </option>
    <option>6 </option>
    <option>7 </option>
    <option>8 </option>
    <option>9 </option>
   <option>10 </option>
    <option>11 </option>
   <option>12</option>
   <option>13</option>
   <option>14</option>
    <option>15 </option>
    <option>16 </option>
    <option>17 </option>
    <option>18 </option>
    <option>19 </option>
    <option>20 </option>
    <option>older than 20 </option>
    </select>
 </td>
</tr>
<br><br>
<tr>
  <td valign="top">What is your favorite Character</td><br>
  <td>
   <input type="radio" name="character" value="Sonic" checked="checked" />Sonic
    <input type="radio" name="character" value="Knuckles" />Knuckles
    <input type="radio" name="character" value="Tails" />Tails
    <input type="radio" name="character" value="Shadow" />Shadow
    <input type="radio" name="character" value="Rouge" />Rouge
    <input type="radio" name="character" value="Eggman" />Eggman
    <input type="radio" name="character" value="Omega" />Omega
    <input type="radio" name="character" value="Metal" />Metal

  </td>
</tr>
<br><br>

<tr>
  <td valign="top">What are your favorite games?</td><br>
  <td>
   <input type="checkbox" name="game" value="Sonic 2D games" />Sonic 2D games<br />
   
    <input type="checkbox" name="game" value="Sonic Adventure 1" />Sonic Adventure 1<br />
    <input type="checkbox" name="game" value="Sonic Adventure 2" />Sonic Adventure 2<br />
      <input type="checkbox" name="game" value="Sonic Heroes" />Sonic Heroes<br />
      <input type="checkbox" name="game" value="Sonic the hedgehog 2006" />Sonic the hedgehog 2006<br />
      <input type="checkbox" name="game" value="Shadow the Hedgehog" />Shadow the Hedgehog<br />
    <input type="checkbox" name="game" value="Sonic and the Secret Rings" />Sonic and the Secret Rings<br />
      <input type="checkbox" name="game" value="Sonic Unleashed" />Sonic Unleashed<br />
 </td>
</tr>
<br>
<tr>
  <td><button type="reset">Reset</button></td>
  <td><button type="submit">Send</button></td><form method="post" name="btnName" onClick ="disp_alert()">
</tr>

</form>
</body>
</html>

Re: Form Scripting problem, help please!

Posted: Sat Jan 03, 2009 10:31 pm
by NuclearSilo

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
</head>
<body>
<script type="text/javascript">
function disp_alert()
{
        var name=document.getElementById("name").value;
        if (name=="") {
                alert("Enter name");
        }
        else {
                window.location="mailto:SonicDX_Adventure@Hotmail.com?subject=Test mail&cc=partenaire@antonio.net&bcc=avocat@antonio.net&body=Hi, how are you?%0D%0AYour name is : "+name;
        }
}
</script>
<form id="form">
<tr>
  <td>Please enter your Name</td><br>
  <td><input type="text" name="name" id="name" size="50" maxlength="35" /></td>
</tr>
<br><br>
<tr>
  <td>What is your age?</td><br>
  <td>
   <select name="age">
   <option>None</option>
    <option>5 </option>
    <option>6 </option>
    <option>7 </option>
    <option>8 </option>
    <option>9 </option>
   <option>10 </option>
    <option>11 </option>
   <option>12</option>
   <option>13</option>
   <option>14</option>
    <option>15 </option>
    <option>16 </option>
    <option>17 </option>
    <option>18 </option>
    <option>19 </option>
    <option>20 </option>
    <option>older than 20 </option>
    </select>
</td>
</tr>
<br><br>
<tr>
  <td valign="top">What is your favorite Character</td><br>
  <td>
   <input type="radio" name="character" value="Sonic" />Sonic
    <input type="radio" name="character" value="Knuckles" />Knuckles
    <input type="radio" name="character" value="Tails" />Tails
    <input type="radio" name="character" value="Shadow" />Shadow
    <input type="radio" name="character" value="Rouge" />Rouge
    <input type="radio" name="character" value="Eggman" />Eggman
    <input type="radio" name="character" value="Omega" />Omega
    <input type="radio" name="character" value="Metal" />Metal
    <input type="radio" name="character" value="Other" checked="checked"/>Other

  </td>
</tr>
<br><br>

<tr>
  <td valign="top">What are your favorite games?</td><br>
  <td>
   <input type="checkbox" name="game" value="Sonic 2D games" />Sonic 2D games<br />
   
    <input type="checkbox" name="game" value="Sonic Adventure 1" />Sonic Adventure 1<br />
    <input type="checkbox" name="game" value="Sonic Adventure 2" />Sonic Adventure 2<br />
      <input type="checkbox" name="game" value="Sonic Heroes" />Sonic Heroes<br />
      <input type="checkbox" name="game" value="Sonic the hedgehog 2006" />Sonic the hedgehog 2006<br />
      <input type="checkbox" name="game" value="Shadow the Hedgehog" />Shadow the Hedgehog<br />
    <input type="checkbox" name="game" value="Sonic and the Secret Rings" />Sonic and the Secret Rings<br />
      <input type="checkbox" name="game" value="Sonic Unleashed" />Sonic Unleashed<br />
</td>
</tr>
<br>
<tr>
  <td><button type="reset">Reset</button></td>
  <td><button type="button" onClick="disp_alert()">Send</button></td>
</tr>

</form>
</body>
</html>

Re: Form Scripting problem, help please!

Posted: Sat Jan 03, 2009 11:36 pm
by poehalcho
let the picture talk.