SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Apr 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with Html (FP) and Javascript

    Hi there everyone.
    I am having some problems with this page www.vinylstickers.com.au/vsop.htm which will later be a part of a page where customers can design and order their vinyl stickers. I had a guy helping me with Javascript cause i know nothing about it, so he wrote some code to display the price in the disabled textbox "subtotal" upon entering a number between 10 and 300 in the "width" field. the price will be calculated according to the width only. what i want is to display that price in the textbox then have it transferred to mal's shopping cart with all other data when the "add to cart" button is clicked. when i first edited this page in FP the price is always displayed correctly, but as soon as i save it and upload it, it stops working and doesn't display. I get an error message in frontpage: "document.StickerCost.txtCost.value; is null or not an object " I can't see what i'm doing wrong and can't get in contact with the guy who wrote the code. Here's a link to the original page that i got from the guy before i edited it and reduced it to only the box that you see in the first link above: www.vinylstickers.com.au/talkfp.htm
    Also i am open to suggestions if anyone knows of a better way to do this. PLEASE help me guys.

  2. #2
    SitePoint Evangelist Alluvian's Avatar
    Join Date
    Jan 2007
    Location
    Orlando, FL
    Posts
    417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not really sure, but try the following:

    Replace line 8
    amt = document.StickerCost.txtCost.value;
    with
    amt = document.getElementById('txtCost').value;

    Replace line 59
    document.StickerCost.txtAmount.value = total_cost;
    with
    document.document.getElementById('txtAmount').value = total_cost;

    THEN
    add
    id="txtAmount"
    and
    id="txtCost"

    to the input tags they apply to. If you are having trouble finding these, they will have name="txtAmount" and name="txtCost" in their tags. The id property can just go right next to that, on either side.

    You also might want to change
    onblur="CalcCost()"
    to
    onchange="CalcCost();"

    Just my suggestions from a noob to a noob. That sourcecode is really hard to read with all the html being spit out with no whitespace.

  3. #3
    SitePoint Member
    Join Date
    Apr 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Alluvian,
    thanks for your suggestion it fixed most of the problem, the price is displayed correctly now and when i add to cart it shows the "width" field content. The only problem i have now is to pass that price to the shopping cart which has to have the name="productpr" to indicate the product price, but don't know what code needs to carry that amount to the cart.
    any ideas?? thanks again.

    Dan

  4. #4
    SitePoint Evangelist Alluvian's Avatar
    Join Date
    Jan 2007
    Location
    Orlando, FL
    Posts
    417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are just filling in input fields on a form on the existing page than just do the same thing:

    document.getElementById('idnameoffield').value = variableorvalue;

    Just make sure you define the id="idnameoffield" property in the html tag. The ids all have to be unique as well.

    If you are passing the data to another page than you would do that like any other form submitted data. (not a javascript issue). If you are trying to track their purchase from page to page without constantly submitting forms for that you either have to do it in the url (not a javascript issue, it is a serverside script issue. php, asp, whatever you run) or you should look into tracking it with sessions in form of cookies (php issue, asp can probably do that as well but I don't know asp from a hole in the wall).


Bookmarks

Posting Permissions

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