Click to See Complete Forum and Search --> : Accessing a form in another page using JavaScript


nebuchadnezzar
05-11-2003, 02:14 AM
Hi!

I'm doing a shopping cart for a University assignment, but I'm having some troubles with one of my functions. I have created a new window, 'order', which i have written a form to. This form asks for the name, address, delivery options and payment method, and then is submitted and returned to the orderForm function. (This function is located on the main page, in the 'trolley' frame... How would I access this too?)

My issue is, that when looking in the JavaScript debugger in Mozilla, I see this:

order.form has no properties

Here's the code for the function that generates the pop-up page with the form:


function order() {

order = window.concat("", "order", "width=600,height=500,toolbar=yes");

with (order.document) {
write("<html><title>Green Grocer Online Shopping Cart</title>");
write("<head><link href='styles.css' rel='stylesheet' type='text/css'></head>");
write("<body bgcolor=#FFFFFF><center>");
write("Please enter your information for delivery:");
write("<form action='' name='order'>");
write("<table width='400' border='0' cellspacing='0' cellpadding='0'>");
write("<tr><td>Name: </td><td><input name='name' type='text' value=''></input></td></tr>");
write("<tr><td>Address: </td><td><input name='address' type='text' value=''></input></td></tr>");
write("<tr><td>Payment Method: </td>");
write("<td><select name='paymentList' onChange='MM_jumpMenu('parent',this,0)'>");
write("<option>Visa</option>");
write("<option>Mastercard</option>");
write("<option>AMEX</option>");
write("<option>Money Order</option></td></tr>");
write("<tr><td>Delivery Method: </td>");
write("<td><select name='deliveryList' onChange='MM_jumpMenu('parent',this,0)'>");
write("<option>Metropolitan Sydney (Weekday) - $5.00</option>");
write("<option>Metropolitan Sydney (Weekend) - $7.00</option>");
write("<option>Greater Sydney (Weekday) - $6.00</option>");
write("</select></td></tr>");
write("</table>");
write("<input name='submit' type='submit' onClick='mainPage.frames.trolley.orderForm(deliveryType, deliveryPrice, name, address payMethod, order)'></form>");
}

var name = order.form.name.value;

var address = order.form.address.value;

var delivery = order.form.deliveryList.selectedIndex;

var payment = order.form.paymentList.selectedIndex;

switch (delivery) {
case 0 :
deliveryType = "Metropolitan Sydney (Weekday)";
deliveryPrice = 5;
break
case 1 :
deliveryType = "Metropolitan Sydney (Weekend)";
deliveryPrice = 7;
break
case 2 :
deliveryType = "Greater Sydney (Weekday)";
deliveryPrice = 6;
break
}

switch (payment) {
case 0 :
payMethod = "Visa";
break
case 1 :
payMethod = "Mastercard";
break
case 2 :
payMethod = "AMEX";
break
case 3 :
payMethod = "Money Order";
break
}
}


Can anyone enlighten me as to why it's not working? I'm not quite sure how to reference that new page...

Any help would be greatly, greatly appreciated!

Thanks!

gil davis
05-11-2003, 07:34 AM
Originally posted by nebuchadnezzar
order.form has no propertiesThat usually means it doesn't exist in the DOM.order = window.concat("", "order", "width=600,height=500,toolbar=yes");This is not a standard javascript function, and you did not include its definition in your post. If you expected this function to open a new window, the correct function would beorder = window.open(...);You also need to close the document after you are finished writing to it. It is safest to use the full syntax:order.document.close();outside of the with statement.

nebuchadnezzar
05-11-2003, 10:50 PM
Originally posted by gil davis
That usually means it doesn't exist in the DOM.This is not a standard javascript function, and you did not include its definition in your post. If you expected this function to open a new window, the correct function would beorder = window.concat(...);You also need to close the document after you are finished writing to it. It is safest to use the full syntax:order.document.close();outside of the with statement.

OK... if I wanted to open a new window, how would I do it then? I just saw it in an example on some website. I'll make sure to close the document as well.

As for the frame named 'order', I hadn't meant it to appear like that. I have one page with 3 frames, and all of the JavaScript located in one of the frames, 'trolley'. I have a link in there to place an order, which calls the 'order' function, and opens the window (the code shown before), called 'order' (which I'll change to orderWindow). The user then fills out a form on this page, and presses Submit. What I would like to do is gather the values of the 2 text fields and 2 select boxes, and then pass them onto the orderForm function, which displays a page (in the same window) with that information.

I can post orderForm too, if needed.

Any other suggestions?

Thankyou very much for your help, guys, I appreciate it!

nebuchadnezzar
05-12-2003, 09:00 AM
Not the same error, at least... I decided to scrap that order function, and instead write an HTML page to display within the frames of the main page, which calls 'parent.frames.trolley.printForm' when submitted. This seems to be working fine, except that two of the values I try to pass to printForm, name and address, are not displayed. The other two are, however (paymentList and deliveryList, which use drop-down menus).

Instead of the name and address, I get this:

Customer name: [object HTMLInputElement]

Address: [object HTMLInputElement]

While payMethod and deliveryType (& Price) display fine.

I'm uploading the site as I type this... Should be viewable at http://www.cse.unsw.edu.au/~jlhi471/CIS/index.html

The page in question can be accessed by pressing the "Place Order" link in the bottom frame.

Thankyou very much!

---

I should also note that I do not have all of the entries on the site working yet, but I have enabled the first 3 items on the 'Fruits' page, which can be checked, if you feel so inclined to test it out...

I also just tried pressing "View Cart" and "Place Order" in Safari (on MacOS X), and it didn't work (didn't open a window)... How would I be able to fix this? (It's using window.open right now.)

xinran
05-12-2003, 10:18 AM
you should change the function call to :
printForm(name.value, address.value, paymentList.selectedIndex, deliveryList.selectedIndex)

if you want to pass from a new openned window, you should call in the new openned window as:
opener.parent......