Passing javascript variable to next php page -


so have php file form located.

<head> <script src="js/create_competition.js" type="text/javascript"></script> </head> <body> <form id='create-competition' action='create_competition_action.php' method='post' accept-charset='utf-8'>      <div id="main">     <input type="button" id="addbutton" value="add" class="bt" />     </div>      <input type='submit' id='submit' name='submit' value='submit' /> </body> 

and when press add button field created on page. when press again, field created , on. , when field created variable in create_competition.js gets bigger 1.

now when lets there 3 field created , after submit button pressed want pass variable (which 3 @ moment) create_competition_action.php use knowledge of how many fields created there. have no idea how can that.

i tried using in create_competition.js

$('#submit').click(function(){       alert(nrfields); // see if works       window.location.href = "create_competition_action.php?var=" + nrfields;     }) 

alert worked, after pressing submit got alert of how many fields created window.location.href did not. other have not found solutions on how it.

you have typo error in function. alerting nrfield , appending nrfields s @ end.

but if need count iteration or simmilar, can use arrays:

 <input type="text" name="values[]" /> 

and in php

 foreach($_post["values"] $value) ... 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -