I am trying to change the value of the variable "hard" according to
which radio button is pressed and I am having no joy. Could anyone
help me with this, the problematic section is marked with
***********************, I've included all the code incase that isn't
where the problem is.
Any help would be hugely appreciated.
Mick
<HTML>
<HEAD>
<TITLE>Products List</TITLE>
<SCRIPT LANGUAGE="JavaScript">
var items = new Array(10);
var numitems = 0;
function Item(d,c,q,w,h) {
this.desc = d;
this.price = c;
this.quantity = q;
this.wrap = w;
this.hard = h;
}
function additem(desc,price,quantity,wrap,hard) {
items[++numitems] = new Item(desc,price,quantity,wrap,hard);
displaycart();
}
function removeitem() {
///confirms the removal of the last item
if (confirm("\nAre you sure?\n")) {
(numitems--);
displaycart();
}
}
function displaycart() {
var totalcost=0;
with (parent.cart.document) {
open();
write("<HTML><BODY>");
write("<H1>Shopping Cart</H1><HR>");
if (numitems==0) {
write("No items ordered.");
close();
return;
}
write("<TABLE BORDER=1><FORM NAME='form1'>");
for(i=1;i<=numitems;i++) {
write("<TR><TD>");
//the following input box has been modified so that the
//quantity cannot be altered
write("<INPUT NAME='qty' TYPE='TEXT' onfocus='this.disabled=true'
SIZE=2 VALUE=");
write(items[i].quantity + ">");
write("<TD>" + items[i].desc);
write("<TD>£" + items[i].price);
write("<TD>£" + (items[i].price * items[i].quantity));
write("<TD>back" +(items[i].hard));
///////////////
write("<TR>");
write("<TD bgcolor='silver'>");
write("<TD><p>wrap cost</p>");
write("<TD>HARD " +(items[i].hard));
write("<TD>");
write("<TD>£" + (items[i].wrap));
////////////////
// write("<TD>" + (items[i].picture);
write("</TR>\n");
totalcost += (items[i].price *
items[i].quantity+items[i].wrap);
}
totalcost = Math.floor(totalcost*100) /100;
write("<TR><TD COLSPAN=3><B>Total Cost:</B>");
write("<TD>" + totalcost);
write("</TABLE>");
write("<INPUT TYPE=BUTTON VALUE='Update'");
write("onClick='parent.products.updatecart();'>");
write("<INPUT TYPE=BUTTON VALUE='Complete Order'");
write("onClick='parent.products.complete();'>");
//removeitem button
write("<INPUT TYPE=BUTTON VALUE='Remove last item'");
write("onClick='parent.products.removeitem();'>");
write("</FORM></HTML>");
close();
<!--
//currency button
//<form onClick="currency=getRadioValue(this.op_sys);self. alert('The
conversion rate from Sterling is '+currency );">
//<input type="RADIO" name="op_sys" value="1"> Sterling<br>
//<input type="RADIO" name="op_sys" value="1.8248"> Dollar<br>
//<input type="RADIO" name="op_sys" value="1.3662"> Euro<br>
-->
}
}
function updatecart() {
for (i=1; i<=numitems;i++) {
if (numitems == 1)
items[i].quantity = parent.cart.document.form1.qty.value;
else items[i].quantity = parent.cart.document.form1.qty[i-1].value;
}
displaycart();
}
function complete() {
OrdWin=window.open('cart_complete.htm','OrdWin');
}
function wrapping(selectObject){
var val;
var si=selectObject.selectedIndex;
if (si<0) val=null;
else val=selectObject.options[si].value;
return val;
}
</SCRIPT>
</HEAD>
<BODY onLoad="displaycart();">
<IMG SRC="logo.gif" alt="The Good Sports Guide"><BR>
<H1>Products</H1>
<table border="3">
<th colspan="4">The following products are available online. Click the
ORDER NOW link to order a product.</th>
<tr>
<td>
<P><B>The Good Tennis Guide</B></P>
</td>
<td>
//////////////
<script>
function getRadioValue(radioObject) {
var val = null;
for (var i=0; i<radioObject.length;i++) {
if (radioObject[i].checked) val = radioObject[i].value;
}
return val;
}
</script>
</form>
<B>Price:</B>
</td>
<td>
//////
<p>
<script>
wrap=0;
</script>
<select name="bookwrapping"
onchange="if(this.selectedIndex)wrap=+(this[this.selectedIndex].value);">
<option value="not selected" selected disabled></option>
<option value ="0">none</option>
<option value="2.95">Standard Wrapping</option>
<option value="3.95">Deluxe Wrapping</option>
************************************************** *****************************************
<p>Please enter the type of book that you wish to purchase:</p>
<input type="radio" name="radiobutton" value="0"
onclick"if(this.selectedIndex)hard=+(this[this.selectedIndex].value);"/>
<label>Hard Back</label>
<input type="radio" name="radiobutton" value="3"
onclick"if(this.selectedIndex)hard=+(this[this.selectedIndex].value);"/>
<label>Paper Back</label>
</td>
<td>
<INPUT TYPE="BUTTON" VALUE='Add to Cart'
onClick="javascript:additem('tennis', 5.95,1,wrap,hard);");>
</td>
<td>
<img src="image1.gif" width="50" length="75" alt="The Good Tennis
Guide"></A>
</td>
</tr>
<!--
<tr>
<td>
<P><B>The Good Football Guide</B> </P>
</td>
<td>
<B>Price: £5.95</B>
</td>
<td>
<p>test</p>
</td>
<td>
<INPUT TYPE="BUTTON" VALUE='Add to
Cart'onClick="javascript:additem('footie', 5.95,1);");>
</td>
<td>
<img src="image2.gif" width="50" length="75" alt="The Good
Football Guide"></A>
</td>
</tr>
<tr>
<td>
<P><B>The Good Golf Guide RRP: £5.95</B> </P>
</td>
<td>
<B>Price: £5.95</B>
</td>
<td>
<p>test</p>
</td>
<td>
<INPUT TYPE="BUTTON" VALUE='Add to
Cart'onClick="javascript:additem('golf', 5.95,1);");>
</td>
<td>
<img src="image3.gif" width="50" length="75" alt="The Good Golf
Guide"></A>
</td>
</tr>
-->
</table>
</BODY>
</HTML> 1 3199
MickG wrote: I am trying to change the value of the variable "hard" according to which radio button is pressed and I am having no joy. Could anyone help me with this, the problematic section is marked with ***********************, I've included all the code incase that isn't where the problem is.
Any help would be hugely appreciated.
Mick
<HTML> <HEAD> <TITLE>Products List</TITLE> <SCRIPT LANGUAGE="JavaScript">
The script language attribute is depreciated, use type
<script type="text/javascript">
[...] } write("<TABLE BORDER=1><FORM NAME='form1'>");
Quotes around attribute values are not essential under most
conditions, however it is generally a good practice to include
them for all attributes.
write("<TABLE BORDER='1'><FORM NAME='form1'>");
for(i=1;i<=numitems;i++) { write("<TR><TD>"); //the following input box has been modified so that the //quantity cannot be altered write("<INPUT NAME='qty' TYPE='TEXT' onfocus='this.disabled=true' SIZE=2 VALUE=");
Do not use tabs when posting code. Use 1 or 2 spaces for
indenting and manually wrap code at about 65 characters:
for(i=1;i<=numitems;i++) {
write("<TR><TD>");
//the following input box has been modified so that the
//quantity cannot be altered
write("<INPUT NAME='qty' TYPE='TEXT' "
+ "onfocus='this.disabled=true'> SIZE='2' VALUE=");
write(items[i].quantity + ">"); write("<TD>" + items[i].desc); write("<TD>£" + items[i].price); write("<TD>£" + (items[i].price * items[i].quantity)); write("<TD>back" +(items[i].hard)); /////////////// write("<TR>"); write("<TD bgcolor='silver'>"); write("<TD><p>wrap cost</p>"); write("<TD>HARD " +(items[i].hard)); write("<TD>"); write("<TD>£" + (items[i].wrap));
This will generate invalid HTML - where are the closing tags?
It will likely render OK in most browsers though.
[...] write("</FORM></HTML>"); close(); <!--
These are comment markers for HTML, not JavaScript. Use /* */
for blocks or // for lines.
//currency button //<form onClick="currency=getRadioValue(this.op_sys);self. alert('The conversion rate from Sterling is '+currency );">
If this is wrapped in your code, it will cause an error.
//<input type="RADIO" name="op_sys" value="1"> Sterling<br> //<input type="RADIO" name="op_sys" value="1.8248"> Dollar<br> //<input type="RADIO" name="op_sys" value="1.3662"> Euro<br> --> } } function updatecart() { for (i=1; i<=numitems;i++) {
You have used 'i' in multiple functions as a global but with
local context. This is somewhat dangerous, if it's a local,
keep it local
for (var i=1; i<=numitems;i++) {
if (numitems == 1) items[i].quantity = parent.cart.document.form1.qty.value; else items[i].quantity = parent.cart.document.form1.qty[i-1].value; }
For simpler code maintenance, it is good to include all braces:
if (numitems == 1){
items[i].quantity = parent.cart.document.form1.qty.value;
} else {
items[i].quantity =
parent.cart.document.form1.qty[i-1].value;
}
[...] ////////////// <script>
<script type="text/javascript>
function getRadioValue(radioObject) { var val = null;
for (var i=0; i<radioObject.length;i++) { if (radioObject[i].checked) val = radioObject[i].value; } return val; }
The following will be a much faster version of the above:
function getRadioValue(radioObject) {
var i = radioObject.length, val = null;
while (i--) {
if (radioObject[i].checked){
return radioObject[i].value;
}
}
// Should never reach here since one button must always
// be checked, but just in case...
return val;
}
[...] ************************************************** ***************************************** <p>Please enter the type of book that you wish to purchase:</p>
<input type="radio" name="radiobutton" value="0" onclick"if(this.selectedIndex)hard=+(this[this.selectedIndex].value);"/> <label>Hard Back</label> <input type="radio" name="radiobutton" value="3" onclick"if(this.selectedIndex)hard=+(this[this.selectedIndex].value);"/>
You have syntax errors in your onclick code, and the '/' on you
tag ends is for XHTML, not HTML, so don't use them.
Try:
<input type="radio" name="radiobutton" value="0" onclick="
if(this.selectedIndex) {
hard = +(this[this.selectedIndex].value);
}
">
<label>Hard Back<label>
<input type="radio" name="radiobutton" value="3" onclick=
"if(this.selectedIndex) {
hard = +(this[this.selectedIndex].value);
}
"> <label>Paper Back</label>
</td>
<td> <INPUT TYPE="BUTTON" VALUE='Add to Cart' onClick="javascript:additem('tennis', 5.95,1,wrap,hard);");>
javascript pseudo protocol is not required, ditch the extra ';'
onClick="additem('tennis', 5.95,1,wrap,hard);")>
[...]
There may be other errors... see how you go.
--
Rob This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Matt |
last post by:
I have radio buttons on a form, and when the user makes the selection, it
will trigger the event and send the form to the web server and print the
selected value. In Case 1, I just use submit...
|
by: steve |
last post by:
Sorry if I have post this two times.
Hi all
What I'm trying to achieve is:
I have a form with two radio buttons,
if a visitors check radio button 2 and click submit in the next page
radio...
|
by: Oscar Monteiro |
last post by:
I Have to sets of Radio buttons like so:
<input type="radio" name=p1 value=1>
<input type="radio" name=p1 value=2>
<input type="radio" name=p1 value=3>
<br>
<input type="radio" name=p2 value=1>...
|
by: Ferret Face |
last post by:
Hello,
I have a web page that gets the user to select items from a list of options. This list is a set of independant Radio Buttons. I did not use a Radio Button List because I wanted the...
|
by: David Cameron |
last post by:
I noticed
that using an HTMLInputRadioButton and specifying a value to be an empty
string (""), this is overridden by ASP.Net which set the value of the
control to be the same as the ID of the...
|
by: IchBin |
last post by:
I can not see what the problem is with this script. I am just trying to
set a radio button by calling setCheckedValue('abbr_letter', 'V'). Sorry
I am new to javascript.
<html>
<head>
<script...
|
by: IchBin |
last post by:
I am trying to set the state of a radio button. I do not see what I am
doing wrong. Sorry, I am new at this.. I need another set of eyes to
look at this snip of code. I am trying to set the radio...
|
by: Eric Layman |
last post by:
Hi,
I have a radio button and a combo box.
Upon changing a value for radio button, the combo box values will be
dynamically updated.
I have an idea on how to go abt doing it but Im stuck...
|
by: rjlorenzo |
last post by:
Good Day,
I just need help on my programming. I would like to try to retrieved/edit the data i've save using radio button and want it to displayed on radio button for editing or changing the...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |