egiblock Posted July 27, 2009 Share Posted July 27, 2009 i'm pulling hole scores from a database. variable names are h1,h2,h3.....etc.... so my database pull code for display is: <?php echo $row_CourseDetail['h1']; ?> but i also want to generate hidden form values for this at the same time. so i was trying this: <script type="text/javascript"> <!-- Calculate the Scores for Hole Calculations var i=1; var j=18; var ParScore = new Array(); while (i<=j) { document.write('<input type="hidden" value="<?php echo $row_CourseDetail['h1']; ?>">'); i++; } </script> ovbiosusly i want the "h1" variable name in there to be different depending on the loop it's going through. so it should be h + variable 'i' but i can't get the code to process right. any ideas ? Link to comment https://forums.phpfreaks.com/topic/167620-generate-a-hidden-form-values-from-database-pull/ Share on other sites More sharing options...
gevans Posted July 27, 2009 Share Posted July 27, 2009 Why aren't you just using php to do this? <?php $i=1; $j=18; $ParScore = array(); while ($i<=$j) { echo('<input type="hidden" value="'.$row_CourseDetail['h'.$i].'">'); $i++; } Link to comment https://forums.phpfreaks.com/topic/167620-generate-a-hidden-form-values-from-database-pull/#findComment-883915 Share on other sites More sharing options...
abazoskib Posted July 27, 2009 Share Posted July 27, 2009 and if you must do it in javascript, use the '+' operator to concatenate strings for each new variable. Link to comment https://forums.phpfreaks.com/topic/167620-generate-a-hidden-form-values-from-database-pull/#findComment-883938 Share on other sites More sharing options...
haku Posted July 27, 2009 Share Posted July 27, 2009 The '+' sign is used for concatenating javascript, but the problem here is that he wants to output a php value based on a javascript loop - this can't be done. Gevans had the most viable suggestion - doing the loop in PHP. It could be done with AJAX as well. Link to comment https://forums.phpfreaks.com/topic/167620-generate-a-hidden-form-values-from-database-pull/#findComment-883962 Share on other sites More sharing options...
egiblock Posted July 28, 2009 Author Share Posted July 28, 2009 Why aren't you just using php to do this? <?php $i=1; $j=18; $ParScore = array(); while ($i<=$j) { echo('<input type="hidden" value="'.$row_CourseDetail['h'.$i].'">'); $i++; } honestly i just started working with php about 2 weeks ago.. i have no clue what i am doing.. but i got it now. thanks ! Link to comment https://forums.phpfreaks.com/topic/167620-generate-a-hidden-form-values-from-database-pull/#findComment-885206 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.