954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Show price in field when radio button or checkbox is selected.

I am working on a registration form for a conference. The form has several sections of radio buttons and checkboxes and I would like to have it set up so that if a radio button or checkbox is selected the price related to that selection shows up in the rigjt column of the form and can then be totaled up at the bottom of the page.

So, looking for assistance with the javascript (assuming javascript is the best way to do this) for:

1. Show price in field.
2. Total up all of the prices at the bottom of the page.

Any help would be greatly appreciated.

You can view the registration form at:

http://asclsregionviii.org/wpi/imss_09_reg.php

J.R. Constance

jrconstance
Newbie Poster
15 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

You could try this code:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<?xml-stylesheet type="text/css" href="#css21" media="screen"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html id="xhtml10S" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://www.w3.org/2005/10/profile">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="Window-target" content="_top" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<title>Free Live Help!</title>
<style id="css21" type="text/css" media="screen">
/* <![CDATA[ */
table {
   border : none;
   border-collapse : collapse;
   color : #708090;
   width : 80%; }
th {
   padding : .300em;
   border-bottom : 1px solid #aaa;
   border-top : 1px solid #aaa; } 
td {
   border-bottom : 1px solid #aaa;
   background-color : #f5f5f5;
   padding : .200em;
   letter-spacing : 3px;
   text-align : center;
   vertical-align : middle; }
/* ]]> */
</style> 
<script id="javascript1.5" type="text/javascript">
// <![CDATA[
var showPrice = function() {
   var numspan = (( "getElementsByTagName" in document ) ? document.getElementsByTagName("span") : document.all.tags("span") );

   var ids = this.id.match(/\d+/)[ 0 ];
   var span = (( "getElementById" in document ) ? document.getElementById("tot" + ids ) : document.all[ "tot" + ids ] );
   var overallAmount = (( "getElementById" in document ) ? document.getElementById("overall") : document.all.overall );
   span.innerHTML = "";
   var amt = this.value * 1;
   var qty = (( "getElementById" in document ) ? document.getElementById("item" + ids ) : document.all[ "item" + ids ] ).value *1;
   var total = ""; 
   total = (( !qty ) ? 0 : (( qty ) * amt ));

   if ( this.checked && qty ) {
   span.innerHTML = "<span style=\"color : #E00;\">" + total + "</span>";
   overallAmount.innerHTML = (( numspan["tot0"].innerText * 1 ) + numspan["tot1"].innerText * 1 );
   return true; } 
   alert( "Please specify the quantity of selected ( item #" + (( ids * 1 ) + 1 ) + " )." );
   this.checked = false;
   return false;
};

var products = function() {
   var form;
   try { 
   form = document.forms.testform;
   } catch( e ) {
   form = (( "getElementById" in document ) ? document.getElementById("testform") : document.all.testform );
   }
   var oLen = form.elements.length;
   for ( var x = 0; x < oLen; x++ ) {
      if ( "addEventListener" in window ) {
         if ( form.elements[ x ].type === "checkbox" ) {
         form.elements[ x ].addEventListener( "click", showPrice, false );
         continue
         }
      } else if ( "attachEvent" in window ) {
         if ( form.elements[ x ].type === "checkbox" ) {
         form.elements[ x ].attachEvent( "onclick", showPrice );
         continue
         } 
      } if ( form.elements[ x ].type === "checkbox" ) {
      form.elements[ x ].onclick = showPrice;
      continue;
      } 
   } 
};

window.onload = products;
// ]]>
</script>
</head>
<body>
<div id="main">
<form id="testform" action="#" onsubmit="return false;">
<table id="testtable" frame="void" rules="none" summary="Javascript :: Live Demo!">
<tr>
<th>Add</th><th>Item</th><th>Qty.</th><th>Amount</th></tr>
<tr>
<td><input type="checkbox" id="chb0" name="chb0" value="1.25" /></td>
<td>Sample Item #1</td>
<td><input type="text" id="item0" name="item0" value="" size="6" maxlength="5" /></td>
<td><span id="tot0"></span></td>
</tr>
<tr>
<td><input type="checkbox" id="chb1" name="chb1" value="3.25" /></td>
<td>Sample Item #2</td>
<td><input type="text" id="item1" name="item1" value="" size="6" maxlength="5" /></td>
<td><span id="tot1"></span></td>
</tr>
<tr>
<td style="background-color : #fff; border : none;"></td>
<td style="background-color : #fff; border : none;"></td>
<td style="background-color : #fff; border : none;"></td>
<td style="background-color : #fff; border : none;"><span id="overall" style="color : #E00; font-weight : bold; border : none;"></span></td>
</tr>
</table>
</form>
</div>
</body>
</html>


hope it helps...

essential
Posting Shark
974 posts since Aug 2008
Reputation Points: 114
Solved Threads: 138
 

Thanks. This works well for the checkbox that I have that has a quantity.

A couple more questions, though:

1. How to do this if the quantity is always going to be 1. Wouldn't need to have a field to add quantity.

2. How to do this for an array of radio buttons where the $$ value would be different for each radio button.

Thx

jrconstance
Newbie Poster
15 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

It depends' in the concept of your needs.

Try to post a short form sample code, including some of the elements you need that will take part in the entire form processing including detailed instructions.

Then i'll handle all the coding into it.

essential
Posting Shark
974 posts since Aug 2008
Reputation Points: 114
Solved Threads: 138
 

Thanks.

OK, first off, this is a php page with a form that gathers information that is written to a MySQL database. All buiilt using Adobe Dreamweaver Developer's Toolbox. That php/MySQL functionality all works and everything writes to the db as required.

Here is a sample of the code:

<form method="post" id="form1" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>">
      <table width="720" cellpadding="2" cellspacing="0" class="KT_tngtable">
       <tr>
          <td class="KT_th">3-Day Package:</td>
          <td>Includes all general sessions, all exhibit events, lunches, and
            afternoon Breakout Sessions on Thursday, Friday, and Saturday.
        <td>        </tr>
        <tr>
          <td width="180" class="KT_th"><label for="reg3day_1"></label></td>
          <td><div>
              <input <?php if (!(strcmp(KT_escapeAttribute($row_rsregistrant['reg3day']),"ASCLS Member"))) {echo "CHECKED";} ?> type="radio" name="reg3day" id="reg3day_1" value="ASCLS Member" />
              <label for="reg3day_1">ASCLS Professional I or II Member ($210.00)</label>
            </div>
              <div>
                <input <?php if (!(strcmp(KT_escapeAttribute($row_rsregistrant['reg3day']),"ASCLS Collaborative"))) {echo "CHECKED";} ?> type="radio" name="reg3day" id="reg3day_2" value="ASCLS Collaborative" />
                <label for="reg3day_2">ASCLS Collaborative Member ($315.00)</label>
              </div>
            <div>
                <input <?php if (!(strcmp(KT_escapeAttribute($row_rsregistrant['reg3day']),"ASCLS Student/Emeritus"))) {echo "CHECKED";} ?> type="radio" name="reg3day" id="reg3day_3" value="ASCLS Student/Emeritus" />
                <label for="reg3day_3">ASCLS Student/Emeritus Member ($140.00)</label>
            </div>
            <?php echo $tNGs->displayFieldError("registrant", "reg3day"); ?> 
        <td>
        </tr>
         <tr>
          <td width="180" class="KT_th"><label for="regExhibits">Exhibits Only:</label></td>
          <td><input  <?php if (!(strcmp(KT_escapeAttribute($row_rsregistrant['regExhibits']),"Y"))) {echo "checked";} ?> type="checkbox" name="regExhibits" id="regExhibits" value="Y" />
            Entrance Fee - One Time Pass, includes food ($25.00)              <?php echo $tNGs->displayFieldError("registrant", "regExhibits"); ?> </td>
          <td>&nbsp;</td>
          </tr>
          </table>
      <input type="hidden" name="regLate" id="regLate" value="<?php echo KT_escapeAttribute($row_rsregistrant['regLate']); ?>" />
    </form>


This includes one array of radio buttons (althought there are several sections of these on the complete form), and also one example of a checkbox that has a $$ value but not a quantity.

Thanks

jrconstance
Newbie Poster
15 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

In looking at what I submitted I realized I had left off the submit function for the form. Here is the correct code for the last few lines of the form.

<tr class="KT_buttons">
          <td colspan="3"><input type="submit" name="KT_Insert1" id="KT_Insert1" value="Insert record" />          </td>
        </tr>
      </table>
      <input type="hidden" name="regLate" id="regLate" value="<?php echo KT_escapeAttribute($row_rsregistrant['regLate']); ?>" />
    </form>
jrconstance
Newbie Poster
15 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

Ok i'll post back your solution later, it's a bit getting late here...

essential

essential
Posting Shark
974 posts since Aug 2008
Reputation Points: 114
Solved Threads: 138
 

Thanks so much.

jrconstance
Newbie Poster
15 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

Hi there,

You can thanked me when we finished this.

If you need some quick brief regarding about getting all the values specified in your radio buttons, then you might want to check back on the showPrice() function provided in my recent sample code.
It deals on the same process and the only difference is the type's of element that we are getting.

You can easily referenced form elements using this method:

var form = document.forms[ /* index or id will work here */ ];

   for ( var x = 0; x < form.elements.length; x++ ) { // Looping throughout the entire form elements.
      if ( form.elements[ x ].type === 'radio' ) { // Let's check/get if this type of element belongs to the radio class.
      form.elements[ x ].onclick = function() { // Break the loop and get those radio types'
      alert( "The value of this radio button is, " + this.value ); // Alerting its value.

      // you may apply more things from here.
      }; // Closing function.
      continue; // continues the loop.
      } // You can get other form elements from here. But not getting the radio types.
   // Coz it was filtered inside the 1st if() block statement.
      alert( form.elements[ x ].type );
   } // End Loop


hope it does explain things clearly, knowing that i am not good on explaining things... :)

essential
Posting Shark
974 posts since Aug 2008
Reputation Points: 114
Solved Threads: 138
 

I can certainly follow the code, and see what you're doing, but I doubt that I would be able to take this and make it work on my own. I just don't have the experience with javascript to be able to do that.

J.R.

jrconstance
Newbie Poster
15 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

Ok here is it...
Note that i've excluded all the PHP block on this demo, so you'll need to put them back again in place.

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<?xml-stylesheet type="text/css" href="#css21" media="screen"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html id="xhtml10S" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://www.w3.org/2005/10/profile">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="Window-Target" content="_top" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<title>Free Live Help!</title>
<style id="css21" type="text/css" media="screen">
/* <![CDATA[ */
table {
  margin : 0 auto;
  color : #405060;
  letter-spacing : 2px;
  border : 1px solid #aaa;
  empty-cells : show;
  border-collapse : collapse;
  width : 98%; }

td { 
  padding : .500em 1em .500em 1em; 
  border-bottom : 1px solid #aaa; }

td:first-child { 
  background-color : #f7f7f7; 
  text-align : center; 
  width : 25%; 
  border-right : medium groove #aaa; 
  padding : 0; }

tr { line-height : 1.6 }

/* ]]> */
</style>
<script id="javascriptV15" type="text/javascript">
// <![CDATA[
var showValue = function() {
   var cel = (( this.type === "radio" ) ? this.parentNode.parentNode.nextSibling : this.parentNode.nextSibling );
   var eVal = (( isNaN( this.value )) ? this.value : this.value * 1 );
   if ( this.checked ) {
   cel.style.color = "#f80";
   cel.innerText = eVal;
   return;
   } cel.innerText = "";
};

var getValue = function() {
   var form;
   try {
   form = document.forms["form1"];
   } catch( e ) {
   form = (( "getElementsByName" in document ) ? document.getElementsByName( "form1" )[ 0 ] : (( "getElementById" in document ) ? document.getElementById("form1") : document.all[ "form1" ] ));
   } var elem = form.elements; 
   for ( var x = 0; x < elem.length; x++ ) {
      if ( elem[ x ].type === "radio" || elem[ x ].type === "checkbox" ) {
         try {
            if ( "addEventListener" in window ) {
            elem[ x ].addEventListener( "click", showValue, false );
            } else if ( "attachEvent" in window ) {
            elem[ x ].attachEvent( "onclick", showValue );
            }             
         } catch( er ) {
         elem[ x ].onclick = showValue;
         } continue;
      }
   }      
};

window.onload = getValue;



// ]]>
</script>
</head>
<body>
<form method="post" id="form1" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>">
<table frame="void" rules="none" cellpadding="2" cellspacing="0" class="KT_tngtable" summary="JavaScript :: Live Demo!">
<tr>
<td class="KT_th">3-Day Package:</td>
<td>Includes all general sessions, all exhibit events, lunches, and afternoon Breakout Sessions on Thursday, Friday, and Saturday.<td>
</tr>
<tr>
<td width="20%" class="KT_th"><label for="reg3day_1"></label></td>
<td><div>
<input type="radio" name="reg3day" id="reg3day_1" value="ASCLS Member" />
<label for="reg3day_1">ASCLS Professional I or II Member ($210.00)</label>
</div>
<div>
<input type="radio" name="reg3day" id="reg3day_2" value="ASCLS Collaborative" />
<label for="reg3day_2">ASCLS Collaborative Member ($315.00)</label>
</div>
<div>
<input type="radio" name="reg3day" id="reg3day_3" value="ASCLS Student/Emeritus" />
<label for="reg3day_3">ASCLS Student/Emeritus Member ($140.00)</label>
</div> 
<td style="width : 25%; text-align : center"></td>
</tr>
<tr>
<td width="20%" class="KT_th"><label for="regExhibits">Exhibits Only:</label></td>
          <td><input  type="checkbox" name="regExhibits" id="regExhibits" value="Y" />
            Entrance Fee - One Time Pass, includes food ($25.00)</td>
<td style="width : 25%; text-align : center"></td>
</tr>
<tr class="KT_buttons">
<td style="border-right : none; width : auto; padding : .500em 1em .500em 1em;" colspan="3"><input type="submit" name="KT_Insert1" id="KT_Insert1" value="Insert record" />
</td>
</tr>
</table>
<input type="hidden" name="regLate" id="regLate" value="" />
</form>
</body>
</html>
essential
Posting Shark
974 posts since Aug 2008
Reputation Points: 114
Solved Threads: 138
 

Thanks. I'll have to look at this later today.

J.R.

jrconstance
Newbie Poster
15 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

I'm not seeing the right hand column where the $$values should be showing up. Am I missing something?

J.R.

jrconstance
Newbie Poster
15 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

essential,

Not sure if you have moved on to something else or not. I am still trying to figure this out since the example you provided does not show the price in the right hand column. Any chance you can take a look at that and get back to me.

I appreciate your assistance with this. Thanks.

jrconstance
Newbie Poster
15 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

Hi jrconstance,

sorry to keep u hanging on this thread. Im just busy with some new project here.

And regarding about displaying its price value, i really need some reference into it, so that i can display each of these values' on their specific field.

essential
Posting Shark
974 posts since Aug 2008
Reputation Points: 114
Solved Threads: 138
 

Here is your original code with the added fields in the form for you to reference:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<?xml-stylesheet type="text/css" href="#css21" media="screen"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html id="xhtml10S" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://www.w3.org/2005/10/profile">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="Window-Target" content="_top" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<title>Free Live Help!</title>
<style id="css21" type="text/css" media="screen">
/* <![CDATA[ */
table {
  margin : 0 auto;
  color : #405060;
  letter-spacing : 2px;
  border : 1px solid #aaa;
  empty-cells : show;
  border-collapse : collapse;
  width : 98%; }

td { 
  padding : .500em 1em .500em 1em; 
  border-bottom : 1px solid #aaa; }

td:first-child { 
  background-color : #f7f7f7; 
  text-align : center; 
  width : 25%; 
  border-right : medium groove #aaa; 
  padding : 0; }

tr { line-height : 1.6 }

/* ]]> */
</style>
<script id="javascriptV15" type="text/javascript">
// <![CDATA[
var showValue = function() {
   var cel = (( this.type === "radio" ) ? this.parentNode.parentNode.nextSibling : this.parentNode.nextSibling );
   var eVal = (( isNaN( this.value )) ? this.value : this.value * 1 );
   if ( this.checked ) {
   cel.style.color = "#f80";
   cel.innerText = eVal;
   return;
   } cel.innerText = "";
};

var getValue = function() {
   var form;
   try {
   form = document.forms["form1"];
   } catch( e ) {
   form = (( "getElementsByName" in document ) ? document.getElementsByName( "form1" )[ 0 ] : (( "getElementById" in document ) ? document.getElementById("form1") : document.all[ "form1" ] ));
   } var elem = form.elements; 
   for ( var x = 0; x < elem.length; x++ ) {
      if ( elem[ x ].type === "radio" || elem[ x ].type === "checkbox" ) {
         try {
            if ( "addEventListener" in window ) {
            elem[ x ].addEventListener( "click", showValue, false );
            } else if ( "attachEvent" in window ) {
            elem[ x ].attachEvent( "onclick", showValue );
            }             
         } catch( er ) {
         elem[ x ].onclick = showValue;
         } continue;
      }
   }      
};

window.onload = getValue;



// ]]>
</script>
</head>
<body>
<form method="post" id="form1" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>">
<table frame="void" rules="none" cellpadding="2" cellspacing="0" class="KT_tngtable" summary="JavaScript :: Live Demo!">
<tr>
<td class="KT_th">3-Day Package:</td>
<td>Includes all general sessions, all exhibit events, lunches, and afternoon Breakout Sessions on Thursday, Friday, and Saturday.<td>
</tr>
<tr>
<td width="20%" class="KT_th"><label for="reg3day_1"></label></td>
<td><div>
<input type="radio" name="reg3day" id="reg3day_1" value="ASCLS Member" />
<label for="reg3day_1">ASCLS Professional I or II Member ($210.00)</label>
</div>
<div>
<input type="radio" name="reg3day" id="reg3day_2" value="ASCLS Collaborative" />
<label for="reg3day_2">ASCLS Collaborative Member ($315.00)</label>
</div>
<div>
<input type="radio" name="reg3day" id="reg3day_3" value="ASCLS Student/Emeritus" />
<label for="reg3day_3">ASCLS Student/Emeritus Member ($140.00)</label>
</div> 
<td style="width : 25%; text-align : center"><input name="reg3dayPrice" type="text" id="reg3dayPrice" size="10" /></td>
</tr>
<tr>
<td width="20%" class="KT_th"><label for="regExhibits">Exhibits Only:</label></td>
          <td><input  type="checkbox" name="regExhibits" id="regExhibits" value="Y" />
            Entrance Fee - One Time Pass, includes food ($25.00)</td>
<td style="width : 25%; text-align : center"><input name="regExhibitsPrice" type="text" id="regExhibitsPrice" size="10" /></td>
</tr>
<tr class="KT_buttons">
<td style="border-right : none; width : auto; padding : .500em 1em .500em 1em;" colspan="3"><input type="submit" name="KT_Insert1" id="KT_Insert1" value="Insert record" />
</td>
</tr>
</table>
<input type="hidden" name="regLate" id="regLate" value="" />
</form>
</body>
</html>
jrconstance
Newbie Poster
15 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

Try this again:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<?xml-stylesheet type="text/css" href="#css21" media="screen"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html id="xhtml10S" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://www.w3.org/2005/10/profile">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="Window-Target" content="_top" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<title>Free Live Help!</title>
<style id="css21" type="text/css" media="screen">
/* <![CDATA[ */
table {
  margin : 0 auto;
  color : #405060;
  letter-spacing : 2px;
  border : 1px solid #aaa;
  empty-cells : show;
  border-collapse : collapse;
  width : 98%; }

td { 
  padding : .500em 1em .500em 1em; 
  border-bottom : 1px solid #aaa; }

td:first-child { 
  background-color : #f7f7f7; 
  text-align : center; 
  width : 25%; 
  border-right : medium groove #aaa; 
  padding : 0; }

tr { line-height : 1.6 }

/* ]]> */
</style>
<script id="javascriptV15" type="text/javascript">
// <![CDATA[
var form;
var showValue = function() { 
   var showPrice = form.reg3dayPrice;
   var exhibits = form.regExhibitsPrice;
   var eVal = this.parentNode.innerText.match( /\$.\d+\.\d+/i )[ 0 ];
   if ( this.checked ) {
      if ( this.type === "radio" ) { 
      showPrice.value = eVal;
      } else if ( this.type === "checkbox" ) {
      exhibits.value = eVal;
      } return;
   } showPrice.value = "";
exhibits.value = "";
}; var getValue = function() {  
   try {
   form = document.forms["form1"];
   } catch( e ) {
   form = (( "getElementsByName" in document ) ? document.getElementsByName( "form1" )[ 0 ] : (( "getElementById" in document ) ? document.getElementById("form1") : document.all[ "form1" ] ));
   } var elem = form.elements;
   for ( var x = 0; x < elem.length; x++ ) {
      if ( elem[ x ].type === "radio" || elem[ x ].type === "checkbox" ) {
         try {
            if ( "addEventListener" in window ) {
            elem[ x ].addEventListener( "click", showValue, false );
            } else if ( "attachEvent" in window ) {
            elem[ x ].attachEvent( "onclick", showValue );
            }             
         } catch( er ) {
         elem[ x ].onclick = showValue;            
         } continue;
      }
   } 
};
window.onload = getValue;
// ]]>
</script>
</head>
<body>
<form method="post" id="form1" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>">
<table frame="void" rules="none" cellpadding="2" cellspacing="0" class="KT_tngtable" summary="JavaScript :: Live Demo!">
<tr>
<td class="KT_th">3-Day Package:</td>
<td>Includes all general sessions, all exhibit events, lunches, and afternoon Breakout Sessions on Thursday, Friday, and Saturday.<td>
</tr>
<tr>
<td width="20%" class="KT_th"><label for="reg3day_1"></label></td>
<td><div>
<input type="radio" name="reg3day" id="reg3day_1" value="ASCLS Member" />
<label for="reg3day_1">ASCLS Professional I or II Member ($210.00)</label>
</div>
<div>
<input type="radio" name="reg3day" id="reg3day_2" value="ASCLS Collaborative" />
<label for="reg3day_2">ASCLS Collaborative Member ($315.00)</label>
</div>
<div>
<input type="radio" name="reg3day" id="reg3day_3" value="ASCLS Student/Emeritus" />
<label for="reg3day_3">ASCLS Student/Emeritus Member ($140.00)</label>
</div> 
<td style="width : 25%; text-align : center"><input name="reg3dayPrice" type="text" id="reg3dayPrice" size="10" /></td>
</tr>
<tr>
<td width="20%" class="KT_th"><label for="regExhibits">Exhibits Only:</label></td>
          <td><input  type="checkbox" name="regExhibits" id="regExhibits" value="Y" />
            Entrance Fee - One Time Pass, includes food ($25.00)</td>
<td style="width : 25%; text-align : center"><input name="regExhibitsPrice" type="text" id="regExhibitsPrice" size="10" /></td>
</tr>
<tr class="KT_buttons">
<td style="border-right : none; width : auto; padding : .500em 1em .500em 1em;" colspan="3"><input type="submit" name="KT_Insert1" id="KT_Insert1" value="Insert record" />
</td>
</tr>
</table>
<input type="hidden" name="regLate" id="regLate" value="" />
</form>
</body>
</html>
essential
Posting Shark
974 posts since Aug 2008
Reputation Points: 114
Solved Threads: 138
 

Still not working, but I think I now understand how this is supposed to work. When you said:

"And regarding about displaying its price value, i really need some reference into it, so that i can display each of these values' on their specific field."

were you saying that you need both a hidden reference somewhere in the form with the actual price of the item, along with the field in which this price would be displayed? If that's the case, I am wondering how best to set up the reference fields, especially for the radio buttons. I can certainly create a hidden field for that but not sure how to do that with an array of buttons. Can we create an array with the costs somewhere in the javascript?

jrconstance
Newbie Poster
15 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

Yes, that would be possible. I'll try to provide you with another example later....

essential
Posting Shark
974 posts since Aug 2008
Reputation Points: 114
Solved Threads: 138
 

This comes with predefined price values:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<?xml-stylesheet type="text/css" href="#css21" media="screen"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="xhtml10S" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://www.w3.org/2005/10/profile">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="Window-Target" content="_top" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<title>Free Live Help!</title>
<style id="css21" type="text/css" media="screen">
/* <![CDATA[ */
table {
  margin : 0 auto;
  color : #405060;
  letter-spacing : 2px;
  border : 1px solid #aaa;
  empty-cells : show;
  border-collapse : collapse;
  width : 98%; }

td { 
  padding : .500em 1em .500em 1em; 
  border-bottom : 1px solid #aaa; }

td:first-child { 
  background-color : #f7f7f7; 
  text-align : center; 
  width : 25%; 
  border-right : medium groove #aaa; 
  padding : 0; }

tr { line-height : 1.6 }

/* ]]> */
</style>
<script id="javascriptV15" type="text/javascript">
// <![CDATA[
var field1, field2;

var price = { // Specify the following price value for this element.

reg3day_1 : "$210.00",
reg3day_2 : "$315.00",
reg3day_3 : "$140.00",
regExhibits : "$25.00"
};

var showValue = function( ids ) {
   field2 = (( document.getElementById ) ? document.getElementById("regExhibitsPrice") : document.all.regExhibitsPrice );
   if ( this.checked && this.type === "radio" ) {
      field1.value = price[ this.id ];
   } else { 
        if ( typeof ids !== "undefined" ) { 
      field2.value = (( field2.value === price[ ids ] ) ? "" : price[ ids ] );
      }
   }
};

var getValue = function() {
var check = true;
   field1 = (( document.getElementById ) ? document.getElementById("reg3dayPrice") : document.all.reg3dayPrice );
var iRadio;
   try {
      if ( document.getElementsByName ) { 
      iRadio = document.getElementsByName( "reg3day" );
      } 
   } catch( e ) {
   check = false;
   iRadio = (( document.getElementsByTagName ) ? document.getElementsByTagName("input") : document.all.tags("input"));
   } for ( var x = 0; x < (( check ) ? iRadio.length : 3 ); x++ ) {
      if ( check ) {
      iRadio[ x ].onclick = showValue;
      } else {
      iRadio[ "reg3day_" + (( x ) + 1 ) ].onclick = showValue;
      }
   }
};
window.onload = getValue;
  
// ]]>
</script>
</head>
<body>
<form method="post" id="form1" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>">
<table frame="void" rules="none" cellpadding="2" cellspacing="0" class="KT_tngtable" summary="JavaScript :: Live Demo!">
<tr>
<td class="KT_th">3-Day Package:</td>
<td>Includes all general sessions, all exhibit events, lunches, and afternoon Breakout Sessions on Thursday, Friday, and Saturday.<td>
</tr>
<tr>
<td width="20%" class="KT_th"><label for="reg3day_1"></label></td>
<td><div>
<input type="radio" name="reg3day" id="reg3day_1" value="ASCLS Member" />
<label for="reg3day_1">ASCLS Professional I or II Member ($210.00)</label>
</div>
<div>
<input type="radio" name="reg3day" id="reg3day_2" value="ASCLS Collaborative" />
<label for="reg3day_2">ASCLS Collaborative Member ($315.00)</label>
</div>
<div>
<input type="radio" name="reg3day" id="reg3day_3" value="ASCLS Student/Emeritus" />
<label for="reg3day_3">ASCLS Student/Emeritus Member ($140.00)</label>
</div> 
<td style="width : 25%; text-align : center"><input name="reg3dayPrice" type="text" id="reg3dayPrice" size="10" /></td>
</tr>
<tr>
<td width="20%" class="KT_th"><label for="regExhibits">Exhibits Only:</label></td>
          <td><input  type="checkbox" name="regExhibits" id="regExhibits" value="Y" onclick="showValue( this.id );" />
            Entrance Fee - One Time Pass, includes food ($25.00)</td>
<td style="width : 25%; text-align : center"><input name="regExhibitsPrice" type="text" id="regExhibitsPrice" size="10" /></td>
</tr>
<tr class="KT_buttons">
<td style="border-right : none; width : auto; padding : .500em 1em .500em 1em;" colspan="3"><input type="submit" name="KT_Insert1" id="KT_Insert1" value="Insert record" />
</td>
</tr>
</table>
<input type="hidden" name="regLate" id="regLate" value="" />
</form>
</body>
</html>
essential
Posting Shark
974 posts since Aug 2008
Reputation Points: 114
Solved Threads: 138
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You