Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-25-2011, 03:49 AM   PM User | #1
Bigandrewgold
New to the CF scene

 
Join Date: May 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Bigandrewgold is an unknown quantity at this point
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..
Bigandrewgold is offline   Reply With Quote
Old 05-25-2011, 03:53 AM   PM User | #2
bullant
Banned

 
Join Date: Feb 2011
Posts: 2,699
Thanks: 13
Thanked 395 Times in 395 Posts
bullant is on a distinguished road
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?
bullant is offline   Reply With Quote
Old 05-25-2011, 03:58 AM   PM User | #3
Bigandrewgold
New to the CF scene

 
Join Date: May 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Bigandrewgold is an unknown quantity at this point
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.
Bigandrewgold is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:36 PM.


Advertisement
Log in to turn off these ads.