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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    getting a variable from a form to javascript

    so i have this code i am working on(this is a dumbed down version of it)
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html> 
        <head>
        
    
      <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
        <script type="text/javascript">
            $(function(){
                $("#Submit").click(function(){
    			for (i=0;i<=50;i++)
    			{
                    $.ajax({
                        url:"process.php",
                        type:"get",
                        data:$("form").serialize(),
                        success:function(response){
                            var obj = jQuery.parseJSON( response );
                            var success = obj.success;
                            var actionsNumber = obj.number;
                            $("#result").html('There have been  '+actionsNumber+'  loops completed');    
    				
    
                        }
                    })
                }
    			
    			})
            })
        </script>
        </head>
      <body>
        <form action="" method="post">
        <p>
        <label><strong>Number of Loops</label>
        </p>
       <input name="count" type="text" value = "1"/>
        </p>
        
        <p>
        <input id="Submit" type = "button" value = "Send">
        </p>
        </form>
        <p id="result">There have been 0 loops completed</p>
        </body></html>
    so you see this for loop

    for (i=0;i<=50;i++)

    I want it to be able to be like

    for (i=0;i<=count;i++)

    so that it will loop the number of times inputted

    also(though i dont know if this is something that i need to use js for) On my full code there are other textboxes that need to be sent to process.php each time that it is run.


    How can i achieve this?


    also before anyone asks i have googled this and searched around yet i havent been able to figure this out, everything i have tried hasnt worked

    and here is the process.php

    PHP Code:
    <?php session_start();
    // process the form data here
    //:::::::::
    //
    if(!isset($_SESSION['number'])){
          
    $_SESSION['number'] = 0;
        }
    $number =  $_SESSION['number']++;

    // output json response 
    echo'{"success":"true","number":"'.$number.'"}';
    ?>
    Last edited by Bigandrewgold; 05-25-2011 at 06:46 AM.

  • #2
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    It looks to me like you got this code from somewhere and are now looking for someone to fix it for you.

    Where is your closing form tag?

  • #3
    New to the CF scene
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by bullant View Post
    It looks to me like you got this code from somewhere and are now looking for someone to fix it for you.

    Where is your closing form tag?
    No. I wrote this myself. I just deleted a bunch of stuff from it to post so I must of accidently deleted it. No need to assume stuff.


  •  

    Posting Permissions

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