Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Mar 2003
    Location
    U.S.A.
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Checking which form submitting data

    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

  • #2
    Regular Coder
    Join Date
    Sep 2002
    Location
    Louisiana
    Posts
    576
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how are you calling the script?

  • #3
    New Coder
    Join Date
    Mar 2003
    Location
    U.S.A.
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Here is some code

    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

  • #4
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...

  • #5
    New Coder
    Join Date
    Mar 2003
    Location
    U.S.A.
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks for the reply. I get an error . .

    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

  • #6
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #7
    New Coder
    Join Date
    Mar 2003
    Location
    U.S.A.
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Thank you much!

    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •