| | |
Show price in field when radio button or checkbox is selected.
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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.
Note that i've excluded all the PHP block on this demo, so you'll need to put them back again in place.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<?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>
•
•
Join Date: May 2008
Posts: 15
Reputation:
Solved Threads: 0
Here is your original code with the added fields in the form for you to reference:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<?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>
Try this again:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<?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>
•
•
Join Date: May 2008
Posts: 15
Reputation:
Solved Threads: 0
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?
"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?
This comes with predefined price values:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<?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>
![]() |
Similar Threads
- radio button looses the selected state after validation (JavaScript / DHTML / AJAX)
- make a radio button checked if it was selected before (PHP)
- problem in checking focus of radio button (JavaScript / DHTML / AJAX)
- checkbox or radio button value cant keep during recordset paging function (ASP)
- Validating radio button selection for login redirect (JavaScript / DHTML / AJAX)
- need help how to add multiple email addresses on a radio button (ASP)
- Function to Create Radio Button (JavaScript / DHTML / AJAX)
- Testing Which Radio Button is selected (ASP.NET)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: error handling for AJAX div
- Next Thread: Simple button swap linking different pages
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate automatically beta box browser bug captchaformproblem checkbox close codes createrange() css cursor debugger decimal dependent disablefirebug dom download dropdown editor element engine enter error events explorer ext file firefox form forms frameworks getselection google gwt hiddenvalue hint html htmlform ie7 ie8 iframe index internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jsp jump listbox maps masterpage math media menu microsoft mp4 object onmouseoutdivproblem onreadystatechange paypal php player position problem programming progressbar prototype redirect regex runtime safari scale scriptlets search security select size software sql text textarea unicode w3c window windowofwords windowsxp wysiwyg \n





