Submit Button Needs To Be Clicked Twice To Get My Results From Radio Buttons In A Php Script
The problem with this code is that I can't read the results in $survey_Answers1 except after clicking on the submit button twice. file:survey.php
Solution 1:
Try to insert after for-loop
for ($i = 1; $i <= 2; $i++)
{
// your code here
}
if (empty($_POST['h2'])) $_POST['h2'] = $survey_Answers1; // insert this line
Or use JavaScript, insert to the end of file:
<scriptsrc="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script><script>
$(function(){
if ($('form').length > 0) {
$('form').submit(function(e){
var answers = '';
$('input[type=Radio]:checked').each(function() {
if (answers !== '') {
answers += ',';
}
answers += $(this).val();
})
$('input[name=h2]').val(answers);
});
}
})
</script>
Solution 2:
From what I see your problem is with your for loop try to see whats returning survey_Answers1 in each loop. you can try this to see whats returning each time it loops and part from there
if (isset($_POST[$qNum])){
$survey_Answers1 = $survey_Answers1.', '.$_POST["$qNum"];
?>
<script type="text/javascript"><?phpecho$survey_Answers1; ?></script>
<?php
}
Post a Comment for "Submit Button Needs To Be Clicked Twice To Get My Results From Radio Buttons In A Php Script"