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 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form Validation (Radio Buttons...)

    Hi Guys,

    I have created a very simple form with a text box and radio buttons. I am using javascript to echo my php in a div but it won't allow me to see which radio button was selected! Nightmare... :-(

    Code:
    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    
    <form id="testForm" method="post" >
    
    <input type="text" name="info" >info<br>
    <input type="radio" name="sex" value="male">Male<br>
    <input type="radio" name="sex" value="female">Female
    
    <input type="submit" value="Submit">
    </form> 
    
    <div id="response">
    dafadf
             	<div class="clearer"></div><!--clearer-->
                
             </div><!--response--> 
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="js/testForm.js"></script>
     
    </body>
    </html>
    Code:
    testForm.js file
    
    $(document).ready(function()
    {
    	$("#testForm").submit(function()
    	{
    		
    		var sex_Js = $("#sex").val();
    		
    		var info_Js = $("#info").val();
    	
    		
    		$("#response").load("../testPhp.php",{
    		
    		sex:sex_Js,
    		
    		info:info_Js
    	
    		});
    		
    	return false;
    	});
    	
    });
    PHP Code:
     <?php


        $nameField_PHP 
    $_POST['sex']; 
        
        
    $info_PHP $_POST['info']; 
        
            echo 
    $info_PHP;
            echo 
    "<br />" $nameField_PHP;
        
        
    ?>
    Why isn't the javascript sending the radio buttons value through to the PHP?

    Many thanks.

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    I'm not sure, I don't have a lot of time to look at the code, but I do know that jQuery should be loaded within the head tags.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #3
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    Code:
    $("#sex").val();
    this line indicated an element with an ID of "sex", your inputs do nto have id's assigned.

  • #4
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    you could try is this way as well.

    Code:
    $(document).ready(function()
    {
    	$("#testForm").submit(function(e)
    	{	
                              e.preventDefault();
    		var data = $(this).serializeArray()
    		$("#response").load("../testPhp.php,data);
    		
    	});
    	
    });


  •  

    Posting Permissions

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