Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    May 2007
    Location
    Indonesia
    Posts
    164
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Need help with form in asp

    Hi was wandering if anyone could help me with my form, I need it to be processed and have user names written to a text file the code is in html format and I kinda need asp code to process it ie write to textfile.Please help as I am still experimenting. here is da form and script within the appropriate head tags.
    Code:
    <head>
    <script language=javascript>
    function checkWholeForm(frm) {
       var why="";
       why += first_name(frm.fn.value);
       why += last_name(frm.ln.value);
       why += checkAdd(frm.add.value);
       why += check_ph(frm.ph.value);
       why += checkEmail(frm.em.value);
       
    function first_name (strng){
    var error="";
    if (strng=="") {
       error = "First name field empty.\n";
       alert(error)
    }
    }
    function last_name (strng){
    var error="";
    if (strng=="") {
       error = "Last name field empty.\n";
       alert(error)
    }
    }
    function checkAdd (strng){
    var error="";
    if (strng =="") {
       error = "Address field empty.\n";
       alert(error)
    }
    }
    function check_ph (strng) {
    var error = "";
    if (strng == "") {
       error = "Phone number field empty.\n";
       alert(error)
    }
    
    var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
        if (isNaN(parseInt(stripped))) {
           error = "The phone number contains illegal characters.";
      
        }
        if (!(stripped.length == 10)) {
    	error = "The phone number is the wrong length. Make sure you included an area code.\n";
        } 
    alert(error)
    return error;
    }
    
      
    function checkEmail (strng) {
    var error = "";
    if (strng == "") {
       error = "Email field is empty.\n";
      alert(error)
    }
    
    var emailFilter=/^.+@.+\..{2,3}$/;   // includes blank field
        if (!(emailFilter.test(strng))&&(strng !="")) {
           error = "Please enter a valid email address.\n";
           
    }
    
        else {
    //test email for illegal chars
           var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
           if (strng.match(illegalChars)) {
            error="The email address contains illegal characters.\n";
    
            }
          }
    alert(error)
    return error;
    }
    }
    </script>
    </head>
    <form name=frm action="" onsubmit="return checkWholeForm(frm)">
    First name:&nbsp;<input type=text name=fn><br>
    Last name:&nbsp;<input type=text name=ln><br>
    Address:&nbsp;<input type=text name=add><br>
    Phone:&nbsp;<input type=text name=ph><br>
    Email address:&nbsp;<input type=text name=em><br><br>&nbsp;&nbsp;&nbsp;<input type=submit name=sb value=Submit>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type=reset name=rb value=Clear>
    </form>

  • #2
    Regular Coder
    Join Date
    Mar 2007
    Posts
    505
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Using JS to do your error checking is not the best practice, but should be only one of multiple versions of error checking.

    Remember, there are people out there who do browse sites w/ JS turn OFF.

    But, to answer your question, you would use the Scripting.FileSystemObject.

    This would be done after the HEAD tags, but before the BODY tags.

    Here's the MSDN link to the FileSystemObject. http://msdn2.microsoft.com/en-us/library/d6dw7aeh.aspx
    To say my fate is not tied to your fate is like saying, 'Your end of the boat is sinking.' -- Hugh Downs
    Please, if you found my post helpful, pay it forward. Go and help someone else today.

  • #3
    New Coder
    Join Date
    Sep 2007
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Your submit button has no action. It has a validator tied into the java but you are not sending this any where after that.

    So right now it will do what ever you want the validatior to do but then what?

    process the form?
    send the form fields to a ASP page for processing and display a think you?


  • #4
    Regular Coder
    Join Date
    May 2007
    Location
    Indonesia
    Posts
    164
    Thanks
    10
    Thanked 0 Times in 0 Posts
    quite new to asp I just want the form values displayed as output on html page get it still delving into it though.

  • #5
    Regular Coder
    Join Date
    Mar 2007
    Posts
    505
    Thanks
    1
    Thanked 19 Times in 19 Posts
    If you just want to display the objects, then you can use the REQUEST method.

    Try this simple form first (notice the uppercase change to your form):

    Code:
    <%
    ' To display form values you can use the REQUEST OBJECT, one item at a time
    '
    if request.form("First") <> "" then
      response.write("First Name: " & request.form("First") & "<br />" & vbCrLf)
      '...
      '...
    end if
    '
    ' OR you can use a FOR NEXT Loop to display the values
    ' 
    for each fld in request.form
      response.write(fld & ": " & request.form(fld) & "<br />")
    next
    %>
    
    <form METHOD=POST name=frm action="">
    First name:&nbsp;<input type=text name=fn><br>
    Last name:&nbsp;<input type=text name=ln><br>
    Address:&nbsp;<input type=text name=add><br>
    Phone:&nbsp;<input type=text name=ph><br>
    Email address:&nbsp;<input type=text name=em><br><br>&nbsp;&nbsp;&nbsp;<input type=submit name=sb value=Submit>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type=reset name=rb value=Clear>
    </form>
    To say my fate is not tied to your fate is like saying, 'Your end of the boat is sinking.' -- Hugh Downs
    Please, if you found my post helpful, pay it forward. Go and help someone else today.

  • #6
    Regular Coder
    Join Date
    May 2007
    Location
    Indonesia
    Posts
    164
    Thanks
    10
    Thanked 0 Times in 0 Posts

    thanks

    Quote Originally Posted by Daemonspyre View Post
    If you just want to display the objects, then you can use the REQUEST method.

    Try this simple form first (notice the uppercase change to your form):

    Code:
    <%
    ' To display form values you can use the REQUEST OBJECT, one item at a time
    '
    if request.form("First") <> "" then
      response.write("First Name: " & request.form("First") & "<br />" & vbCrLf)
      '...
      '...
    end if
    '
    ' OR you can use a FOR NEXT Loop to display the values
    ' 
    for each fld in request.form
      response.write(fld & ": " & request.form(fld) & "<br />")
    next
    %>
    
    <form METHOD=POST name=frm action="">
    First name:&nbsp;<input type=text name=fn><br>
    Last name:&nbsp;<input type=text name=ln><br>
    Address:&nbsp;<input type=text name=add><br>
    Phone:&nbsp;<input type=text name=ph><br>
    Email address:&nbsp;<input type=text name=em><br><br>&nbsp;&nbsp;&nbsp;<input type=submit name=sb value=Submit>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type=reset name=rb value=Clear>
    </form>
    will give it a go

  • #7
    Regular Coder
    Join Date
    May 2007
    Location
    Indonesia
    Posts
    164
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Created a dummy html form and used response.write(First name: " & fn(button name) & " to return text input and it work found w3schools website to be of some use. thanks for the help though


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •