#1
  1. No Profile Picture
    hum...
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Brazil
    Posts
    24
    Rep Power
    0

    sending form with javascript


    I need help...
    The validation works fine, but the script not send it...

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    
    <html>
    <head>
    	<title>Form Test</title>
    <script language="JavaScript" type="text/javascript">
    var invalidaddress=new Array()
    //invalidaddress[0]="hotmail"
    //ivalidaddress[1]="rocketmail"
    //invalidaddress[2]="yahoo"
    //invalidaddress[3]="zdnetmail"
    //extend or shorten this list if neccessary
    
    var testresults2
    function checkemail(){
    
    if (document.newsletter.txt_nome.value=='') {
     alert(Type your name!');
     document.newsletter.txt_nome.focus();
     return false;
    }
    
    var invalidcheck=0;
    var str=document.newsletter.txt_email.value
    var filter=/^.+@.+\..{2,3}$/
    
    if (filter.test(str)){
    var tempstring=str.split("@")
    tempstring=tempstring[1].split(".")
    for (i=0;i<invalidaddress.length;i++){
    if (tempstring[0]==invalidaddress[i])
    invalidcheck=1
    }
    if (invalidcheck!=1)
    testresults=true
    else{
    alert("Domain error")
    testresults=false
    }
    }
    else{
    alert("Type a valid email")
     document.newsletter.txt_email.focus();
    testresults=false
    }
    return (testresults)
    }
    
    function checkbae(){
    if (document.layers||document.all)
    	if (checkemail() == true) {
    	document.newsletter.submit()
    	}
    }
    </script>
    </head>
    
    <body>
    
    <center>
    <table width="126" cellspacing="0" cellpadding="0" border="0">
    <form method="post" name="newsletter" action="form.asp">
    <tr>
        <td align="center" class="txt7">Form test</td>
    </tr>
    <tr>
        <td align="center" height="27"><input type="text" name="txt_nome" value="" class="input1"></td>
    </tr>
    <tr>
        <td align="center" height="27"><input type="text" name="txt_email" value="" class="input1"></td>
    </tr>
    <tr>
        <td align="center" height="30" valign="top">
        <a href="javascript:;" onclick="checkbae()"><img src="http://www.caixa.gov.br/_images/icaixa/botaoOkSeguro.gif" alt="" border="0"></a>
         </td>
    </tr>
    </form>
    </table>
    </center>
    
    </body>
    </html>
    Thanks in advance!
    Ricardo
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2003
    Location
    Italy, EU
    Posts
    517
    Rep Power
    12
    I guess it's just this... change the anchor tag you've inserted:
    Code:
    <a href="java script:;" onclick="checkbae()">
    with this one:
    Code:
    <a href="#" onclick="javascript:checkbae()">
    because I think it's trying to execute a javascript that's undefined in the HREF property instead of the one defined by the onClick statement (where you forgot to specify it's a java script!)

    Cheers, Dave
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Location
    Jenbach, Austria
    Posts
    39
    Rep Power
    14

    try this


    hi,

    try this
    PHP Code:
    <form name="formname" id="formname" action="formaction" onsubmit="return checkform();"
    this will submit your form only if checform() returns true.

    hope this helps ...
    welcome to the real world
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Location
    Jenbach, Austria
    Posts
    39
    Rep Power
    14

    try this


    hi,

    try this:

    PHP Code:
    <form method="post" name="newsletter" action="form.asp" onsubmit="return checkbae();"
    this will submit your form only if checkbae() returns true.
    you also need a button type "submit"

    PHP Code:
    <input type="submit" ...> 

    hope this helps ...
    Last edited by MaGast; June 21st, 2003 at 04:19 PM.
    welcome to the real world
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    60
    Rep Power
    12
    So what this script does is send the information without having to send the user to another page? Instead it sends it immediately after clicking submit?
  10. #6
  11. No Profile Picture
    hum...
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Brazil
    Posts
    24
    Rep Power
    0
    Hi! Thanks for all help!

    Magma, the code

    Code:
    <a href="javascript:;" onclick="checkbae()">
    I change to

    Code:
    <a href="#" onclick="checkbae()">
    and it works!
    Don't need to use 'javascript:' on onClick event. In IE6 works fine without this.

    MaGast, thanks for your help too! I can't use submit button because I will use a image with SwapImage script to submit the form. I forgot to explain this, sorry.

    mrbob, this script must send the user to other page, and this is the problem.

    Thanks for all!!!
    Regards,
    Ricardo

IMN logo majestic logo threadwatch logo seochat tools logo