Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    18
    Thanks
    7
    Thanked 0 Times in 0 Posts

    hidden value based on checkbox

    I have a form that has a checkbox that I want to base a hidden value on. If the checkbox is checked I want the hidden value to be 25. If not checked, I want the value to be 0. I am working with code someone else has written and I am fairly new to javascript and cannot get it to work.
    Here is the code on the form:
    <code>
    <td><input type="checkbox" name="binderdiscount" value="Yes" <?php /*?><?php if ($pgdata['binderdiscount']=='Yes') echo 'checked'; ?><?php */?> />I do not need a book;</td>

    <input type="hidden" name="binder_discount" value="0">
    </code>

    and then in a separate page is all the javascript to process the form. I have this, but it is not working.
    <code>
    if(getControlValue(form.binderdiscount)==="Yes") {form.binder_discount.value=25;}
    </code>

    As I said, i am really new to javascript and I am working with someone else's code. All the research I have done has just confused me more about why it is not working. Any help would be greatly appreciated.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Code:
    <input type="checkbox" name="binderdiscount" id = "binderdiscount" onclick = "change()">
    <input type="hidden" name="binder_discount" id = "binder_discount" value = 0>
    
    <script type = "text/javascript">
    function change() {
    if (document.getElementById("binderdiscount").checked) {
    document.getElementById("binder_discount").value = 25;
    }
    else {
    document.getElementById("binder_discount").value = 0;
    }
    
    }
    </script>
    Many people would say that it is not a good idea to give two elements such similar names, binderdiscount and binder_discount.


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    Banned
    Join Date
    Mar 2012
    Posts
    306
    Thanks
    1
    Thanked 28 Times in 28 Posts
    Quote Originally Posted by learning curve View Post
    Any help would be greatly appreciated.
    What you are trying to do lends itself nicely to using a ternary to set the hidden value.

    PHP Code:
                <input onclick="changeHiddenInput(this);" type="checkbox" name="chk1" value="Yes" <?php if ($pgdata['binderdiscount'] == 'Yes') {echo 'checked="checked"';} ?>/>I do not need a book
                <input type="hidden" name="hid1" id = "hid1" value = "<?php echo ($pgdata['binderdiscount'] == 'Yes') ? 25 0 ?>" />
                <script>
                    function changeHiddenInput(elem){
                        document.getElementById('hid1').value = (elem.checked)? 25 : 0;
                    }
                </script>
    It's inefficient to run document.getElementById() 3 times. It's more efficient to pass the checkbox object to the function using the this keyword and then with a ternary you need to call document.getElementById only once.
    Last edited by Mishu; 03-27-2012 at 03:11 AM.

  • Users who have thanked Mishu for this post:

    learning curve (03-29-2012)

  • #4
    New Coder
    Join Date
    Mar 2012
    Posts
    18
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Sorry, the solution from Philip didn't seem to work. It correctly placed a yes or no based on the checkbox, but didn't change binder_discount from 0 to 25. and Mishu, I appreciate your help, but I am afraid I am just new enough it confused me more than helped. I will do some more investigating and see what I can come up with.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by learning curve View Post
    Sorry, the solution from Philip didn't seem to work. It correctly placed a yes or no based on the checkbox, but didn't change binder_discount from 0 to 25.
    Sorry, it works for me. I do not post untested code which does not work. When I add the test line
    alert (document.getElementById("binder_discount").value);
    I get 25 or 0 as appropriate (checked/unchecked).

    No idea what you mean by "placed a yes or no".

    Mishu's suggestions re efficiency are bull****. Any difference in exeuction time is not measurable even in milliseconds, and as you have found his code (ternary operator) is harder to understand.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,620
    Thanks
    0
    Thanked 645 Times in 635 Posts
    If you only need the final value on the server then no JavaScript at all is required.


    Code:
    <input type="hidden" name="binderdiscount"  value="0">
    <input type="checkbox" name="binderdiscount" value="25"">
    that will send 0 to the server if the checkbox isn't selected and will send 25 if it is selected.

    Note that both fields must have the same name for this to work and be specified in this order since only the last field for each name is sent to the server and checkboxes and radio buttons are ignored unless they are selected.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #7
    Banned
    Join Date
    Mar 2012
    Posts
    306
    Thanks
    1
    Thanked 28 Times in 28 Posts
    Quote Originally Posted by learning curve View Post
    and Mishu, I appreciate your help, but I am afraid I am just new enough it confused me more than helped. I will do some more investigating and see what I can come up with.
    That's ok At least you have seen something new. A ternary can be a very useful and efficient operator and I use it a lot.

    Here is a simple explanation and tutorial
    on how it works.

    Quote Originally Posted by learning curve View Post
    Sorry, the solution from Philip didn't seem to work. It correctly placed a yes or no based on the checkbox, but didn't change binder_discount from 0 to 25.
    That's because in your code you have php code that sets the checkbox to checked if the php variable == 'yes' and philip's code hard codes a value of 0 to the hidden input whether the checkbox is checked or not which is not correct and that's why the code doesn't work.

    Philip saying
    No idea what you mean by "placed a yes or no".
    appears to show he has no understanding of your php code and so his code is misleading for a start because of the above.

    You just need to add a php ternary to your hidden input similarly to how I did and that should fix the problem.
    Last edited by Mishu; 03-28-2012 at 02:03 AM.

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,184
    Thanks
    75
    Thanked 4,339 Times in 4,305 Posts
    Quote Originally Posted by felgall View Post
    If you only need the final value on the server then no JavaScript at all is required.


    Code:
    <input type="hidden" name="binderdiscount"  value="0">
    <input type="checkbox" name="binderdiscount" value="25"">
    that will send 0 to the server if the checkbox isn't selected and will send 25 if it is selected.
    [/code]
    Ummm...only if you are using PHP.

    If you are using ASP/ASP.NET/JSP, then it will send an *ARRAY* of values to the server.

    Now, that's perfectly okay. You just have to be aware it might be an array and then pick up the first element of the array, if it is.

    So Felgall's html-only solution is elegant, just adapt your server-side code according to what server-side system you are using.

    Bur realistically, it's just as easy in the server-side code if you simply do
    Code:
    <input type="checkbox" name="binderdiscount" value="25"">
    and nothing more. If you don't get any form field by the name "binderdiscount" then you can assume the value is zero, in your server-side code.
    Last edited by Old Pedant; 03-28-2012 at 02:42 AM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    learning curve (03-29-2012)

  • #9
    Banned
    Join Date
    Mar 2012
    Posts
    306
    Thanks
    1
    Thanked 28 Times in 28 Posts
    Quote Originally Posted by Old Pedant View Post
    Bur realistically, it's just as easy in the server-side code if you simply do
    Code:
    <input type="checkbox" name="binderdiscount" value="25"">
    and nothing more. If you don't get any form field by the name "binderdiscount" then you can assume the value is zero, in your server-side code.
    I like this the best but you would still need to add the php code in the input element to set the checkbox initially to checked or unchecked

    PHP Code:
    <input type="checkbox" name="chk1" value="Yes" <?php if ($pgdata['binderdiscount'] == 'Yes') {echo 'checked="checked"';} ?>/>
    And this is a good example of why when something can be done both server and client side then it should always be done server side and not waste time with javascript.

    In this case you don't need javascript at all to send a value of 0 or 25 to the server.
    Last edited by Mishu; 03-28-2012 at 03:51 AM.

  • #10
    New Coder
    Join Date
    Mar 2012
    Posts
    18
    Thanks
    7
    Thanked 0 Times in 0 Posts
    wow! Thanks for all the help. I think I need to clarify something I thought I mentioned but it appears I left out.
    I need the initial checkbox to put a yes or no in a field in the mysql table for a field called binderdiscount. yes=check box is checked

    then I need the hidden field to input either a 25 or a zero in a table field called binder_discount based on the yes/no check.

    The first is working (Yes/No), but the second is not .


    Philip,
    I am sure your code is great and I really appreciate your help. I just don't know enough to make it work for me in the context of my documents. Any failure is strictly on my end.

    Mishu,
    I fee like I am catching on to what you are helping with but it still doesn't work. I think that is because of other javascript that is running and doing things.

    I hate to post so much info, but it might be beneficial here to see exactly what I am dealing with. As I said, I am fairly new to Javascript and I think this page is just overloading my brain it is so full of code. Here is the entire form page:

  • #11
    New Coder
    Join Date
    Mar 2012
    Posts
    18
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Code:
    <?php
    $noYes = array('No'=>'No','Yes'=>'Yes');
    $days = array(
    	'-'=>'Choose date...',
    	'Wednesday'=>'Wednesday, November 14',
    	'Thursday'=>'Thursday, November 15',
    	'Friday'=>'Friday, November 16',
    	'Saturday'=>'Saturday, November 17',
    	'Sunday'=>'Sunday, November 18'
    	);
    $hours = array(''=>'Choose...');
    for ($i=1; $i<=12; $i++) $hours[$i] = $i;
    $minutes = array('00'=>'00','05'=>'05');
    for ($i=10; $i<60; $i+=5) $minutes["$i"] = "$i";
    $ampm = array('am'=>'am','pm'=>'pm');
    
    require 'workshops.php';
    require '../prices_etc.php';
    $workshops = workshopOptions('html');
    
    global $pgdata;
    
    function makeInput($type,$name,$options=NULL,$default='') {	// Quickly makes form inputs with optional default values taken from $pgdata; This function was more useful when we were prefilling more options
    	global $pgdata;
    	switch($type) {
    		case 'text':
    			if ($options!=NULL) $size = $options;
    			else $size = '30';
    			$output = "<input type='text' name='$name' size='$size'";
    			if (isset($pgdata[$name])) $output .= " value='${pgdata[$name]}'";
    			$output .= '>';
    			break;
    		case 'textarea':
    			if ($options!=NULL) $size = $options;
    			else $size = '30';
    			$output = "<textarea name='$name' rows='3' cols='30'>";
    			if (isset($pgdata[$name])) $output .= $pgdata[$name];
    			$output .= '</textarea>';
    			break;
    		case 'checkbox':
    			$output = '';
    			foreach ($options as $key=>$value) {
    				$output .= "<p class='dentin'><input type='checkbox' name='$name' value='$key'";
    				if (isset($pgdata[$name])) {
    					if ($pgdata[$name]==$key) $output .= ' checked';
    				} elseif ($key==$default) $output .= ' checked';
    				$output .= ">$value</p>";
    			}
    			break;
    		case 'radio':
    			$output = '';
    			foreach ($options as $key=>$value) {
    				$output .= "<p class='dentin'><input type='radio' name='$name' value='$key'";
    				if (isset($pgdata[$name])) {
    					if ($pgdata[$name]==$key) $output .= ' checked';
    				} elseif ($key==$default) $output .= ' checked';
    				$output .= ">$value</p>";
    			}
    			break;
    		case 'select':
    			$output = "<select name='$name'>";
    			foreach ($options as $key=>$value) {
    				$output .= "<option value='$key'";
    				if (isset($pgdata[$name])) {
    					if ($pgdata[$name]==$key) $output .= ' selected';
    				} elseif ($key==$default) $output .= ' selected';
    				$output .= ">$value</option>";
    			}
    			$output .= "</select>";
    			break;
    	}
    	return $output;
    }
    ?>
    
    <h3>General information</h3>
    <p>Note: Items marked with a blue bullet will be included in a list of attendee information published in the conference program.</p>
    <table>
    	<tr>
    		<th><span class="publishedInfo">&bull;</span>First name:</th>
    		<td><?php echo makeInput('text','firstname'); ?></td>
    	</tr>
    	<tr>
    		<th><span class="publishedInfo">&bull;</span>Last name:</th>
    		<td><?php echo makeInput('text','lastname'); ?></td>
    	</tr>
    	<tr>
    		<th><span class="publishedInfo">&bull;</span>Your institution:<br><span class="aside">(if retired, former institution)</span></th>
    		<td>
    			<?php echo makeInput('radio','sincere',array('Yes'=>'sincere University'),'No'); ?>
    			<div id="sincereSpecial" class="indented">
    				<?php
    					global $useyear;
                	    $schoolYear = $useyear.'-'.($useyear+1);
    					echo makeInput('radio','sincere_special',array('Grad student/Retiree'=>'I am a graduate student or a retiree (No registration fee)', 'FLC/NFTEP/PEP/GSTEP'=>"I am a member of a CELT FLC, or a member of NFTEP, PEP, or GSTEP during $schoolYear (No registration fee)", 'No'=>'None of the above <strong>($50 registration fee)</strong>'),'No');
    				?></div>
    			<p class='dentin'><input type='radio' name='sincere' value='No' <?php if ($pgdata['sincere']!='Yes') echo 'checked'; ?>>Other:<input type='text' name='institution' size='30' value='<?php echo $pgdata["institution"]; ?>'></p>
    			<div id="otherSpecial" class="indented"><?php echo makeInput('checkbox','other_special',array('Grad student/Retiree'=>'I am a graduate student or a retiree (25% off conference fees)')); ?></div>		</td>
    	</tr>
    	<tr>
    		<th><span class="publishedInfo">&bull;</span>Department:</th>
    		<td><?php echo makeInput('text','department'); ?></td>
    	</tr>
    	<tr>
    		<th>Office street address:<br><span class="aside">(if retired, home address)</span></th>
    		<td><?php echo makeInput('textarea','address'); ?></td>
    	</tr>
    	<tr>
    		<th>City:</th>
    	  <td><?php echo makeInput('text','city'); ?></td>
    	</tr>
    	<tr>
    		<th>State/province:</th>
    		<td><?php echo makeInput('text','state','10'); ?></td>
    	</tr>
    	<tr>
    		<th>Postal/ZIP code:</th>
    	  <td><?php echo makeInput('text','zip','10'); ?></td>
    	</tr>
    	<tr>
    		<th><span class="publishedInfo">&bull;</span>Country:</th>
    		<td><?php echo makeInput('radio','chooseCountry',array('United States'=>'United States', 'Canada'=>'Canada', 'Other:'=>'Other:'.makeInput('text','country')),'United States'); ?></td>
    	</tr>
    	<tr>
    		<th>Office phone:<br>
    	  <span class="aside">(if retired, home phone)</span></th>
    	  <td><?php echo makeInput('text','office_phone','20'); ?></td>
    	</tr>
    	<tr>
    		<th>Home/cell phone:</th>
    		<td><?php echo makeInput('text','cell_phone','20'); ?></td>
    	</tr>
    	<tr>
    		<th><span class="publishedInfo">&bull;</span>Email address:</th>
    		<td><?php echo makeInput('text','email','40'); ?></td>
    	</tr>
    	<tr>
    		<th><span class="publishedInfo">&bull;</span>Position/title:<br><span class="aside">(if not faculty)</span></th>
    		<td><?php echo makeInput('text','position','40'); ?></td>
    	</tr>
    	<tr>
    		<th>First name or nickname:<br><span class="aside">(for nametag)</span></th>
    		<td><?php echo makeInput('text','nickname','20'); ?> <img src="http://celt.sincere.edu/registration/nametag.png" alt="Illustration of how the nickname will appear prominently on the nametag, followed by the full name" title="Illustration of how the nickname will appear prominently on the nametag, followed by the full name"></td>
    	</tr> 
    </table>
     <p>New this year in the Conference's continuing efforts to "go green," we are offering a $25.00 registration fee discount for those who chose to go paperless.  If you opt not to receive the conference binder you will receive $25 off the registration price. The entire Lilly schedule will be available online for viewing electronically.</p>
        <table>
        <tr><th>Binder Discount:</th>
        <td><input type="checkbox" name="binderdiscount" value="Yes"<?php if ($pgdata['binderdiscount']=='Yes') echo 'checked'; ?>/>I do not need a Lilly Conference binder ($25 discount);</td></tr></table>
        
        
    
    
    <div id="regDiv">
    	<h3>Registration Options</h3>
       
    	<table id="regOption">
    		<tr>
    			<th>Conference Registration:</th>
    			<td><?php echo makeInput('radio','registration',array('Entire Conference'=>'Entire conference - $445 ($395 before October 1)','Thursday Workshop'=>'Thursday pre-conference workshop only')); ?></td></tr>
                
    	</table>
        
    	<div id="lillyReg">
    		<table>
    			<tr>
    				<th>Arrival date:</th>
    				<td>
    					<?php echo makeInput('select','arrivedate',$days); ?>
    				</td>
    			</tr>
    			<tr>
    				<th>Departure date:</th>
    				<td>
    					<?php echo makeInput('select','departdate',$days); ?>
    				</td>
    			</tr>
    		</table>
    		<table id="accommodationRow">
    			<tr>
    				<th>Accommodation:</th>
    				<td><?php echo makeInput('radio','accommodation',array('Yes'=>'I want lodging at the conference','No'=>'I will provide my own lodging')); ?></td>
    			</tr>
    		</table>
            <p id="accommodationFull">Conference accommodation is now full. <a href="http://www.units.sincere.edu/lillycon/lodging.shtml" onclick="this.target='_blank';">See what other lodging is available in the area</a> (opens in a new window)</p>
    	</div>
    </div>
    
    <div id="fullAccomod">
    	<h3> Conference Accommodation</h3>
        <p>If you would like a guest to attend the conference with you, please contact us at (513) 529-9266 or <a href="mailto:lillycon@sincere.edu">lillycon@sincere.edu</a> to make arrangements.</p>
         <table>
    		<tr>
    			<th>Occupancy:</th>
    			<td>
    				<?php echo makeInput('radio','occupancy',array('Single'=>'Single occupancy - <span id="lodgingFeeNightly">$</span> per night','Double'=>'Double occupancy with a roommate (two-bed room) - <span id="lodgingFeeNightlyRoommate">$</span> per night, per person')); ?>
    				<div id="occupancyDouble" class="indented">
    					<?php echo makeInput('radio','roommate',array(
    						'Arranged'=>'I have arranged to share a room <span id="arranged_rm">with: '.makeInput('text','rmname',20).' who is planning to arrive on '.makeInput('select','rm_arrive',$days).'</span>',
    						'Assign'=>'Assign me a roommate <span id="roommateSex"> (I am '.makeInput('select','sex',array('-'=>'Choose...','Female'=>'Female','Male'=>'Male')).')</span>'
    					)); ?>				</div>			</td>
    		</tr>
    		<tr id="lodging">
    			<th>Your   lodging choices, in order of preference:</th>
    			<td id="lodgingOptions">
    				<?php if (function_exists('showLodging')) showLodging(); /* For showing results */ ?>			</td>
    		</tr>
    		<tr>
    			<th>Room Options:</th>
    			<td>
    				<?php
    					echo makeInput('checkbox','barrierfree',array('Yes'=>'Barrier-free room'));
    					echo makeInput('checkbox','tdd',array('Yes'=>'TDD'));
    					echo makeInput('checkbox','allergies',array('Yes'=>'Special room due to allergies'));
    				?>			</td>
    		</tr>
    	</table>
    </div>
    
    <div id="thursWorkshops">
    	<h3>Thursday Pre-Conference Workshop Option:</h3>
    	<p class="dentin">The following <a href="http://celt.sincere.edu/lillycon/preconference.php" onclick="this.target='_blank';">Thursday pre-conference workshops</a> (info opens in new window) are available.  Workshop fees includes materials.</p>
    				<p id="noWorkshop" class="dentin"><input type="radio" name="workshop" value="None" <?php if ($pgdata['workshop']=='No') {echo 'checked';} ?> >None (you can contact us later to add a workshop to your registration, if you wish)</p>
    				<?php echo makeInput('radio','workshop',$workshops); ?>
    				<p id="workshopsincere">sincere faculty and staff are elligible to recieve a small grant to cover the cost of this workshop. See the CELT page on <a href="http://www.units.sincere.edu/celt/smallgrants.php" onclick="this.target='_blank';">Small Grants to Improve Teaching</a> for more information (link opens in a new window).</p>
    </div>
    
    <div id="conMeals">
    	<h3>Conference meals</h3>
        <div id="regMeals">
            <p>Select the meals that you would like to eat at conference facilities.  No changes will be accepted later than one week before the conference starts. <span id="sincereMeals">Because dining room seating is limited, please select <strong>only</strong> the meals you will attend.</span></p>
            <p><strong>Meal deal:</strong> Purchase all meals from Friday lunch through Sunday lunch and save <span id="mealDealSavings">$</span>!</p>
          <table id="meals">
            <tr>
              <th>Thursday</th>
                    <th>Friday</th>
                    <th>Saturday</th>
                    <th>Sunday</th>
                    <th>Cost:</th>
                </tr>
            <!-- Except for workshop lunches, these "included" DIVs aren't currently used. Just keeping them here in case they're needed for some later deal. -->
            <tr id="breakfast">
              <td>&nbsp;</td>
                    <td><div class="mealCheck" id="friBreakfastOpt"><?php echo makeInput('checkbox','friBreakfast',array('Yes'=>'Breakfast')); ?></div><div id="friBreakfastInc" class="mealInclude">Breakfast included</div></td>
                    <td><div class="mealCheck" id="satBreakfastOpt"><?php echo makeInput('checkbox','satBreakfast',array('Yes'=>'Breakfast')); ?></div><div id="satBreakfastInc" class="mealInclude">Breakfast included</div></td>
                    <td><div class="mealCheck" id="sunBreakfastOpt"><?php echo makeInput('checkbox','sunBreakfast',array('Yes'=>'Breakfast')); ?></div><div id="sunBreakfastInc" class="mealInclude">Breakfast included</div></td>
                    <td class="cost"><span id="mealFeeBreakfast">$</span> each</td>
            </tr>
            <tr id="lunch">
              <td><div class="mealCheck" id="thursLunchOpt"><?php echo makeInput('checkbox','thursLunch',array('Yes'=>'Lunch')); ?></div><div id="thursLunchInc" class="mealInclude">Lunch included</div></td>
                    <td><div class="mealCheck" id="friLunchOpt"><?php echo makeInput('checkbox','friLunch',array('Yes'=>'Lunch')); ?></div><div id="friLunchInc" class="mealInclude">Lunch included</div></td>
                    <td><div class="mealCheck" id="satLunchOpt"><?php echo makeInput('checkbox','satLunch',array('Yes'=>'Lunch')); ?></div><div id="satLunchInc" class="mealInclude">Lunch included</div></td>
                    <td><div class="mealCheck" id="sunLunchOpt"><?php echo makeInput('checkbox','sunLunch',array('Yes'=>'Lunch')); ?></div><div id="sunLunchInc" class="mealInclude">Lunch included</div></td>
                    <td class="cost"><span id="mealFeeLunch">$</span> each</td>
                </tr>
            <tr id="dinner">
              <td><div class="mealCheck" id="thursDinnerOpt"><?php echo makeInput('checkbox','thursDinner',array('Yes'=>'Dinner')); ?></div><div id="thursDinnerInc" class="mealInclude">Dinner included</div></td>
                    <td><div class="mealCheck" id="friDinnerOpt"><?php echo makeInput('checkbox','friDinner',array('Yes'=>'Dinner')); ?></div><div id="friDinnerInc" class="mealInclude">Dinner included</div></td>
                    <td><div class="mealCheck" id="satDinnerOpt"><?php echo makeInput('checkbox','satDinner',array('Yes'=>'Dinner')); ?></div><div id="satDinnerInc" class="mealInclude">Dinner included</div></td>
                    <td>&nbsp;</td>
                    <td class="cost"><span id="mealFeeDinner">$</span> each</td>
              </tr>
          </table>
        </div>
    	<div id="mealReqs">
    		<p><strong>Meal Requirements:</strong>
    		<?php echo makeInput('select','specialmeal',array('No'=>'No special meal requirements','Vegan'=>'Vegan (no meat or dairy products)','Vegetarian'=>'Vegetarian (same as vegan but includes great desserts)','Lowfat'=>'Low fat (some dairy/some egg)','Diabetic'=>'Diabetic'),'No'); ?></p>
    	</div>
    </div>
    
    
    <div id="journalOffer">
    	<h3>Special Journal discounts</h3>
    	<p>Order a personal one-year (<?php echo date('Y') + 1; ?>) subscription to one of our <cite><a href="http://celt.sincere.edu/journals/" onclick="this.target='_blank';">international, peer-reviewed journals</a></cite> at the <strong>Conference special rate</strong> and save!</p>
    <?php
    	foreach ($regOptions['journalNames'] as $short=>$long) {
    		echo '<div class="eachJournal">';
    		echo "<h3><img src='$short.jpg' alt='Cover of the $long'>$long</h3>";
    		echo "<div id='{$short}NorthAmerica'>";
    		echo makeInput('radio',"{$short}_subscription",array(
    			'Individual - Print'=>"Print ({$regOptions['journalIssuesYr'][$short]} iss./yr.): <span id='{$short}PriceIndividual'></span>",
    			'Individual - Combo'=>"Combination print and electronic: <span id='{$short}PriceCombo'></span>",
    		));
    		echo '</div>';
    		echo makeInput('radio',"{$short}_subscription",array(
    			'Individual - Electronic'=>"Electronic (includes access to all previous issues): <span id='{$short}PriceElectronic'></span>",
    // Not doing inst subscriptions on Lilly form anymore
    // 			'Institutional - Electronic'=>"Institutional site license - electronic: <span id='{$short}PriceInstitutionElectronic'></span>",
    // 			'Institutional - Combo'=>"Institutional site license - combination print and electronic: <span id='{$short}PriceInstitutionCombo'></span>",
    			'No'=>'No thank you'
    		),'No');
    		echo '<div class="nofloat"></div></div>';
    	}
    ?>
    </div>
    
    
    <h3>Total cost and payment options</h3>
    <table><tbody id="lineItems"><tr>
      <td>We are very sorry, but there was an error calculating your total. Please reload this page and try again.</td>
    </tr></tbody></table>
    <p><strong>Total registration cost: $<input name="total" id="total" type="text" value="0" size="8" readonly> (USD)</strong></p>
    
    <div id="payment">
    	<p>Please select one or more of the following methods to pay for your registration:</p>
    	<p class="dentin"><input type="checkbox" name="payment_credit" value="Yes" <?php if ($pgdata['payment_credit']=='Yes') echo 'checked'; ?> >Personal or institutional credit card</p>
    	<div id="payCredit" class="indented">
    		<p class="dentin"><input type="radio" name="payment_online" value="Yes" <?php if ($pgdata['payment_online']=='Yes') echo 'checked'; ?> >I want to pay the full amount online <strong>(Mastercard, Visa, Discover, or American Express)</strong></p>
    		<p class="dentin"><input type="radio" name="payment_online" value="No" <?php if ($pgdata['payment_online']=='No') echo 'checked'; ?> >I will call (513)&nbsp;529-8234 with my credit card information <strong>(Mastercard or Visa only)</strong></p>
    	</div>
    	<p class="dentin"><input type="checkbox" name="payment_personalCheck" value="Yes" <?php if ($pgdata['payment_personalCheck']=='Yes') echo 'checked'; ?> >Personal check</p>
    	<p class="dentin end"><input type="checkbox" name="payment_institutionCheck" value="Yes" <?php if ($pgdata['payment_institutionCheck']=='Yes') echo 'checked'; ?> >Institutional check</p>
    	<div id="payCheck" class="indented">
    		<p>Please make checks out to Sincere University and send it to:</p>
    		<address>sincere University<br>
    			Center for the Enhancement of Learning, Teaching, and University Assessment<br>
    			551 East High St.<br>
    			Sydney, Ohio 45241</address>
    	</div>
    </div>
    
    
    	
    <h3>Print receipt, read refund policy, and submit your registration</h3>
    <p>Before you submit this registration form, please read the refund policy below, review your information and <em><strong>print out this page as your registration receipt</strong></em>, and then mark the checkbox below.  If you make any changes, this box will uncheck itself as a reminder to print out the final version.</p>
    
    <div class="refund">
    	<h3>Refund Policy</h3>
    	<p>If you are unable to attend, someone else may attend in your stead. Otherwise the refund policy is as follows:</p>
    	<ul>
    		<li>By September 30, refund 100% minus $50 cancellation fee</li>
    		<li>Between October 1 and October 31, refund 75% of conference fees or conference fees minus $100, whichever is less</li>
    		<li>After October 31, refund 0%</li>
    	</ul>
    	<p>Make inquiries to:</p>
    	<address>Sincere University<br>
    Center for the Enhancement of Learning, Teaching, and University Assessment</address>
    	<address>
    	551 East High St.<br>
    Sydney, Ohio 45241<br>
    Phone: 513-529-9266<br>
    Email: <a href="mailto:lillycon@sincere.edu">lillycon@sincere.edu</a>
    	</address>
    </div>
    
    <p class="dentin end"><strong><input type="checkbox" id="printed" name="printed" value="Yes" <?php if ($pgdata['printed']=='Yes') echo 'checked'; ?> >I have reviewed my information, agree to the refund policy above, and printed this page as my receipt.</strong></p>
    <p>
    	<input type="hidden" name="full_receipt">
    	<input type="hidden" name="ject_cost" value="0">
    	<input type="hidden" name="lcj_cost" value="0">
    	<input type="hidden" name="jctl_cost" value="0">
    	<input type="hidden" name="earlybird" value="<?php if (date('n')>=10 && date('j')>1) echo '0'; else echo $earlyBirdAmount; ?>">
    	<input type="hidden" name="breakdown_conference_fee" value="0">
    	<input type="hidden" name="breakdown_workshop" value="0">
        <input type="hidden" name="binder_discount" id = "binder_discount" value = "0">
    	<input type="hidden" name="breakdown_wed_supplement" value="0">
    	<input type="hidden" name="breakdown_thurs_supplement" value="0">
    	<input type="hidden" name="breakdown_lodging" value="0">
    	<input type="hidden" name="breakdown_meals" value="0">
    	<input type="hidden" name="breakdown_subtotal" value="0">
    	<input type="hidden" name="breakdown_retiree_grad_discount" value="0">
    </p>
    Last edited by VIPStephan; 03-29-2012 at 01:16 AM. Reason: corrected/added code BB tags

  • #12
    New Coder
    Join Date
    Mar 2012
    Posts
    18
    Thanks
    7
    Thanked 0 Times in 0 Posts
    and here is the javascript processing page attached as a txt file(due to size.)
    Attached Files Attached Files

  • #13
    New Coder
    Join Date
    Mar 2012
    Posts
    18
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Some how the php form didn't make it. Here it is:
    Attached Files Attached Files

  • #14
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,184
    Thanks
    75
    Thanked 4,339 Times in 4,305 Posts
    Well, neither of those files is relevant to how you would modify the PHP code to do what you stated:
    I need the initial checkbox to put a yes or no in a field in the mysql table for a field called binderdiscount. yes=check box is checked

    then I need the hidden field to input either a 25 or a zero in a table field called binder_discount based on the yes/no check.
    You don't show the code that process the <form> data to store it into the MySQL DB.

    It would be trivial to modify the PHP code to do just that, but I'd want to see the relevant code first.

    However...

    Given that your page depends SO HEAVILY on JavaScript, it's clear that you don't really care about users who have JavaScript disabled: your page simply won't work for them.

    So in that case, let's go back to your original question.

    I don't see why your existing code doesn't work.

    Code:
    <input type="checkbox" name="binderdiscount" value="Yes" <?php /*?><?php if ($pgdata['binderdiscount']=='Yes') echo 'checked'; ?><?php */?> />I do not need a book;</td>
    
    <input type="hidden" name="binder_discount" value="0">
    ...
    if(getControlValue(form.binderdiscount)==="Yes") {form.binder_discount.value=25;}
    
    ...
    function getControlValue(control) {
    	var i, output;
    	output = null;
    	if (control.type==="checkbox") {
    		if (control.checked) {
    			output = control.value;
    		}
            ...
            return output;
    }
    Looks perfectly okay to me.

    Maybe you just need to do some JavaScript debugging?

    Use a good JS debugger, set a breakpoint on that line (the first "if" in above code) and see what the values are and what is happening.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #15
    Banned
    Join Date
    Mar 2012
    Posts
    306
    Thanks
    1
    Thanked 28 Times in 28 Posts
    Quote Originally Posted by learning curve View Post
    I need the initial checkbox to put a yes or no in a field in the mysql table for a field called binderdiscount. yes=check box is checked

    then I need the hidden field to input either a 25 or a zero in a table field called binder_discount based on the yes/no check.

    The first is working (Yes/No), but the second is not .
    If the above is not working then you need to post the php code that loads the form data into the database. Have a look at the url in the action attribute of your form and post the code in that url.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •