Skip to main content
Inspiring
January 4, 2013
Question

Php recordset outputting last value from while loop

  • January 4, 2013
  • 1 reply
  • 1173 views

Hi all,

I have an issue with a site I am making which lists radio buttons which are a set of donation options (some with predefined prices some with user dependant).

I used jQuery to populate a textbox with the value of the radio buttons so the person does not need to enter a price they want to donate.

The issue I am having is that I want the page to carry across the fund_id (which is the primary key) to the next page.

Currently the do / while loop goes through all of the recordset and passes across the last record's fund_id.

Please see my code below:

$(function () {

$('input.radioButton').click(function () {

      var checkedradio = $('[name="fund"]:radio:checked').val();

  $('#totalPrice').val(checkedradio);

  });

});

And

<h3>General</h3>
  <?php do { ?>
    <label><input class="radioButton" type="radio" name="fund" value="<?php echo $row_cat_general['fund_price']; ?>" id="<?php echo $row_cat_general['fund_name']; ?>" /><?php echo $row_cat_general['fund_name']; ?> <?php if ($row_cat_general['fund_price']!="") { ?>- &pound;<?php echo $row_cat_general['fund_price']; ?><?php } else {?> <?php };?></label>

    <br />
    <?php } while ($row_cat_general = mysql_fetch_assoc($cat_general)); ?>

<h3>Sponsorship</h3>
  <?php do { ?>
    <label><input class="radioButton" type="radio" name="fund" value="<?php echo $row_cat_sponsorship['fund_price']; ?>" /><?php echo $row_cat_sponsorship['fund_name']; ?> <?php if ($row_cat_sponsorship['fund_price']!="") { ?>- &pound;<?php echo $row_cat_sponsorship['fund_price']; ?><?php } else {?> <?php };?></label>
    <br />
    <?php } while ($row_cat_sponsorship = mysql_fetch_assoc($cat_sponsorship)); ?>

<h3>Seasonal</h3>
  <?php do { ?>
    <label><input class="radioButton" type="radio" name="fund" value="<?php echo $row_cat_seasonal['fund_price']; ?>" /><?php echo $row_cat_seasonal['fund_name']; ?> <?php if ($row_cat_seasonal['fund_price']!="") { ?>- &pound;<?php echo $row_cat_seasonal['fund_price']; ?><?php } else {?> <?php };?></label>
    <br />
    <?php } while ($row_cat_seasonal = mysql_fetch_assoc($cat_seasonal)); ?> 
      <br />
      <span id="sprytextfield1">
      <label>Enter Amount:
        <input name="total" type="text" id="totalPrice" />
      </label>
      <span class="textfieldRequiredMsg">A donation amount is required.</span></span><br />
      <input name="fund_id" type="hidden" value="<?php echo $row_cat_general['fund_id']; ?>" id="fund_id" />
      <input name="button" type="submit" value="Select" />      

I hope this doesnt look weird, once I have post this.

Is there a way I can populate "totalPrice" input box AND have "fund_id" hidden field populated with the fund_id of the selected radio button?

Thanks for your help.

This topic has been closed for replies.

1 reply

Inspiring
January 6, 2013

Can anyone help?

Inspiring
January 6, 2013

Hi,

I have tried this:

$(function () {

$('input.radioButton').click(function () {

      var checkedradio = $('[name="fund"]:radio:checked').val();
  var fundidbox = $('[name="fund_id"]').val();

  $('#totalPrice').val(checkedradio);
  $('#fund_id').val(fundidbox);
  alert($("#fund_id").val());

  });
Inspiring
January 7, 2013

I dont know what I am doing wrong with this