SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2003
    Location
    London
    Posts
    78
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    You Sexy Javascript Genius!?

    Hello,

    I am a Javascript novice and am hoping that someone can help me out on this problem I can't get my head round. I suspect it might have a simple answer (for a genius).

    I have a form which needs two things . . .

    1) A redirect on submission of the form to one of two pages. Which page the user is directed to depends on their checking a box (or leaving it unchecked).

    2) A few fields of the form validated on submission (or before if possible).

    I have two bits of Javascript I have used for the above purposes, but cannot for the life of me get them to both work at the same time. I am wondereing if they could be combined or if there is a simpler answer?

    The relevant code is pasted below (and yes, I know the html is OLD to say the least). I REALLY hope that you can help . . .

    Code:
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <style>
    A:link { text-decoration: none; color: #808080; ; }
    A:visited  { text-decoration: none; color: #404040; ; }
    A:active  { text-decoration: none; color: #008000; ; }
    A:hover  { text-decoration: underline; color: #008000; ; }
    </style>
    
    <script language="JavaScript">
    <!--
    function updateRedirect() {
    if (document.acontact.Updates.checked){
    document.acontact.redirect.value="http://www.sitepoint.com/";
    }
    document.acontact.submit();
    }
    //-->
    </script>
    </head>
    
    <BODY>
    <script language="JavaScript">
    <!--
    
    /*
    Required field(s) validation- By NavSurf
    Visit NavSurf.com at http://navsurf.com
    Visit http://www.dynamicdrive.com for this script
    */
    
    function formCheck(formobj){
    	//1) Enter name of mandatory fields
    	var fieldRequired = Array("First name", "Last name", "email");
    	//2) Enter field description to appear in the dialog box
    	var fieldDescription = Array("First name", "Last name", "E-mail");
    	//3) Enter dialog message
    	var alertMsg = "Please complete the following fields:\n";
    	
    	var l_Msg = alertMsg.length;
    	
    	for (var i = 0; i < fieldRequired.length; i++){
    		var obj = formobj.elements[fieldRequired[i]];
    		if (obj){
    			switch(obj.type){
    			case "select-one":
    				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    				break;
    			case "select-multiple":
    				if (obj.selectedIndex == -1){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    				break;
    			case "text":
    			case "textarea":
    				if (obj.value == "" || obj.value == null){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    				break;
    			default:
    				if (obj.value == "" || obj.value == null){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    			}
    		}
    	}
    
    	if (alertMsg.length == l_Msg){
    		return true;
    	}else{
    		alert(alertMsg);
    		return false;
    	}
    }
    //-->
    </script>
    <CENTER>
    
    
    
    
    <form name="acontact" method="post" action="http://www.blah3636blah.com/cgi-bin/sexy_women.pl" onSubmit="return formCheck(this); updateRedirect();">
      	<input type="hidden" name="recipient" value="kiss_me" />
        <input type="hidden" name="redirect" value="http://www.blah3636blah.com/thankyou.shtml" />
        <input type="hidden" name="subject" value="Contact from blah3636blah" />
     	<input type="hidden" name="sort" value="Order:First name,Last name,Date of Birth,Nationality,Residential Address,Correspondence Address,email,Telephone,Updates,Testingit" />
    
              <font face="Arial, Helvetica, Timesnewroman" size="2" color="#000000"> 
              Please e-mail me updates on future trips* 
              <input type="checkbox" name="Updates" value="Please send me regular blah3636blah updates." />
              <BR>
              <BR>
              First name:<BR>
              <input type="text" name="First name" size="30">
              <BR>
              <BR>
              Last name:<BR>
              <input type="text" name="Last name" size="30">
              <BR>
              <BR>
              Date of Birth:<BR>
              <input type="text" name="Date of Birth" size="20">
              <BR>
              <BR>
              Nationality:<BR>
              <input type="text" name="Nationality" size="20">
              <BR>
              <BR>
              Residential Address:<BR>
              <textarea name="Residential Address" cols="34" rows="5"></textarea>
              <BR>
              <BR>
              Correspondence Address (if different from above):<BR>
              <textarea name="Correspondence Address" cols="34" rows="5"></textarea>
              <BR>
              <BR>
              E-mail:<BR>
              <input type="text" name="email" size="30">
              <BR>
              <BR>
              Telephone:<BR>
              <input type="text" name="Telephone" size="30">
              <BR>
              <BR>
              <BR>
              Please tick <em>everything</em> you are interested in: <BR>
              <BR>
    		  <input type="checkbox" name="Testingit" value="I'm interested. Please contact me.">
              <b><font color="#008000">Testing</font> <font color="#000000">It</font></b><BR>
    		  
              Press the 'Submit' button below.<br>
              <BR>
              We will be in touch with you as soon as possible.<BR>
              <BR>
              <BR>
              <p> 
                <input type="submit" name="submit" value="Submit info to blah3636blah" />
              </p>
              <BR>
              </font> 
            </form>
    
    </body>
    </html>
    Last edited by stymiee; Feb 1, 2008 at 11:34.

  2. #2
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your title is unique, I present you with a standard grade llama in appreciation.

    Anyways, one thing to note is that names must follow the following format:

    ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
    Source: http://www.w3.org/TR/html401/types.html#type-cdata

    That said, you need to fix those for the form validation code. See if that does anything. If not, you can pull up firefox and use the error console feature to see why the browser can't work with your code.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2003
    Location
    London
    Posts
    78
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Merci

    Thanks Chris,

    I've tried as you suggested, but it doen't seem to make any difference

    Any idea (anyone) if the actual coding is correct?

    Sid

    p.s. Thanks for the Llama Chris. How often does it need a tap dance (per day)? And if it dances more than the required amount, will it automatically upgrade itself from standard?

  4. #4
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does your error console say anything? If you use firefox (which I recommend for javascript debugging), then there's an error console that you can use to see where the parser is failing. I'd run it through that and see what it says.

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2003
    Location
    London
    Posts
    78
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Chris,

    Thanks for your rapid reply. How doi I run it through the console? I tried uploading the entire page to my hosting and then putting that address in the Error Console, but all I get is Syntax Error line one, no explanation or anything.

    Thanks again,
    Sid

  6. #6
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh what you do is clear the error console, then visit the page in firefox itself. If there are any errors on the page, then the console will display where the issue is .

  7. #7
    SitePoint Enthusiast
    Join Date
    Nov 2003
    Location
    London
    Posts
    78
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Weird, I can't see any errors. I must be doing something wrong. Can I PM (or email) you the link and you have a look please?

    Many Thanks,

    Sid

  8. #8
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, looking this over:

    1) A redirect on submission of the form to one of two pages. Which page the user is directed to depends on their checking a box (or leaving it unchecked).

    2) A few fields of the form validated on submission (or before if possible).
    For #1, use the server side language for that. Check the value of the checkbox, then do a header (for php, using the header) function with "Location: /the_page_you_want.html".

    For #2, it sounds like you were at least able to get the validation code working. However you'll also want to compliment that on the side with validation on the server side as well. Javascript can be changed at will by the client, so Javascript Validation is not the perfect solution.

  9. #9
    SitePoint Enthusiast
    Join Date
    Nov 2003
    Location
    London
    Posts
    78
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Thank you

    Thank you again Chris,

    Unfortunately point one is beyond me (even with the help from the link you provided (thank you)).

    Has anyone else out there got any idea how I can do this please?

    Many Thanks,
    Sid
    Last edited by Sidney; Feb 7, 2008 at 02:44. Reason: typo


Bookmarks

Posting Permissions

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