...

View Full Version : Checking which form submitting data



SABuddy
03-04-2003, 10:17 PM
Hi,

I am working on a script that changes the price of soap based on additions. I got some great help with that but now I need a way to find out which form is calling the script as the prices differ from form to form.

Any help is appreciated!

TIA,
Riva

chrismiceli
03-05-2003, 01:40 AM
how are you calling the script?

SABuddy
03-05-2003, 02:01 AM
This is the code in the select statement to call the script:

onChange="newMsg(this)"

This is the function being called:

function newMsg(objSelect)

I am just wondering - would this work if I called the script from "onSubmit"? That way it would not have to worry about which form it was although it may not be able to give me the value chosen in the select (the reason the script is called from the select statement.)

Thanks,
Riva

cheesebagpipe
03-05-2003, 02:05 AM
You can get the form object that contains the element the function was called from like this:

function newMsg(objSelect) {
var objForm = objSelect.form;

All form elements have a .form property for just this purpose.

btw you can pretty much get any data about the current document from anywhere...

SABuddy
03-05-2003, 02:12 AM
When I use the code:

var objForm = objSelect.form;
alert(objForm);

the alert box comes up with [object]

Can you help some more? Also, I would love to find out how you can reference anything from anywhere - my shopping cart uses a product[] field making things a little tricky.

Thanks,
Riva

cheesebagpipe
03-05-2003, 02:20 AM
It's not an error; that's your form object! Your original question was in re "I need a way to find out which form is calling the script..." Now that you've got the object, you can read any of its properties easily. Hard to say more as you haven't explained what it is you'd like to do, or how your data is structured.

You'd reference that product[] field the same way:

document.form_name['product[]']

My remark about referencing was just a reassurance - lots of people just getting familiar with client-side programming spend considerable time worrying "is this/that/the other possible?". These days, these browsers, it almost always is - within the constraints that limit web pages, naturally.

SABuddy
03-05-2003, 02:45 AM
I did upload my page to the following URL if you are interested in looking at the coding (it is not the "working" version):

http://pages.ivillage.com/thebubblebath/tester1.html

Thanks again,
Riva



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum