Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Php recordset outputting last value from while loop

Participant ,
Jan 03, 2013 Jan 03, 2013

Copy link to clipboard

Copied

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.

TOPICS
Server side applications

Views

1.1K
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 06, 2013 Jan 06, 2013

Copy link to clipboard

Copied

Can anyone help?

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 06, 2013 Jan 06, 2013

Copy link to clipboard

Copied

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());

  });

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 07, 2013 Jan 07, 2013

Copy link to clipboard

Copied

I dont know what I am doing wrong with this

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 09, 2013 Jan 09, 2013

Copy link to clipboard

Copied

LATEST

Does anyone know of any good donation scripts that have multiple donatable causes?

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines