SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Nov 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    "document.getElementById ('total').value = total;" not submitted in Form Post

    Hi ,

    I have a issue with a javascript code that I wrote. This script is a simply for calculating the summation of 2 text input boxes and printing it in another text input box within the form. The entire form is then sent using Form post

    The total is written back to the form's total text input box using the code below:
    document.getElementById ('total').value = total

    This code works perfectly for displaying the values on screen.

    However, when I send the form (PHP Post), the " total " field is empty.
    I have searched all over for possible solutions. But no solution yet.

    Does anybody have any idea.

    PS: Things I have tried:

    1. document.getElementById ('total').INNERHTML = total
    This does not even work on screen and total field is not updated on screen. Needless to say, the PHP Post variable was also empty.
    Check out our website . Bincom: Nigerian Web Development.
    Also check us for Joomla Nigeria
    Naijaplus
    is a Portal showing everything positively Nigeria

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Make sure you have name="total" on that element, otherwise the browser won't send it when the form is submitted.

    Also, make sure you really change the value before the form is submitted.

  3. #3
    SitePoint Member
    Join Date
    Nov 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well the name of the total element is " form[total] "? Does it have to be absolutely named as the name of my variable ?

    It is as if the browser does not send the field even though the total field is shown correctly on the site. I even tried filling a total manually and the form was sent correctly with all the fields intact.
    Check out our website . Bincom: Nigerian Web Development.
    Also check us for Joomla Nigeria
    Naijaplus
    is a Portal showing everything positively Nigeria

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Post a minimal working example which demonstrates the problem.

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by humanknowledge View Post
    Well the name of the total element is " form[total] "? Does it have to be absolutely named as the name of my variable ?

    It is as if the browser does not send the field even though the total field is shown correctly on the site. I even tried filling a total manually and the form was sent correctly with all the fields intact.
    Try using a program like Charles to monitor the information that gets sent back and forth.

    http://www.charlesproxy.com/

    That way you can easily check that the form data being sent is what you expect.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The name="" attributes in the form define what the names of the fields are when they are passed to the server. If you are using an id to reference fields from JavaScript then you still need a name as well if you want it passed to the server as input fields without names don't get passed. The other group of input fields that don't get passed are those that are disabled.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


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
  •