Get form input total

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tcertain
    New Member
    • Aug 2008
    • 2

    Get form input total

    I am totally duh at javascript although I have 2 books trying to learn it.

    I am trying to add values to a form and have a calculate total at end.
    this is my form script. I have hours at end of each radio or checkmark. (If this is checked, add these hours. ) I want to calculate total at the calculate button at the bottom of the form and have a window that shows the total.

    please excuse the long form, but with all the different variables I thought it wise to post whole thing.

    [HTML]<form method="post" action="">
    <fieldset name="General">
    <legend class="alignlef t">General</legend>
    <p>
    <input name="Have_Site " type="radio" checked="checke d" />&nbsp;&nbsp;
    I have an existing website.&nbsp; (0 hours)</p>
    <p><input name="Have_Site " type="radio" />&nbsp;&nbsp;
    I need a basic blog site.&nbsp; (3 hours)</p>
    <p>
    <input name="Have_Site " type="radio" />&nbsp;
    I need a basic, off the shelf, template based site
    set-up.&nbsp; (6 hours)</p>
    <p><input name="Have_Site " type="radio" />&nbsp; I need a completely custom site.&nbsp; (15 hours)<br />
    </p>
    </fieldset>
    <fieldset name="Site Layout">
    <legend class="alignlef t">Site Layout</legend>
    <p>
    <input name="No_Graphi cs" type="radio" checked="checke d" />&nbsp;
    I do not need any unique graphics designed.&nbsp; &nbsp;
    (0 hours)</p>
    <p><input name="Have_Grap hics" type="radio" />&nbsp; I have all
    my graphics but they need to be integrated. (3 hours)</p>
    <p><input name="Template_ Minor" type="radio" />&nbsp; I have a
    template but it needs minor customization.& nbsp; (6
    hours)</p>
    <p><input name="Template_ Major" type="radio" />&nbsp; I have a
    template but it needs major custimzation.&n bsp; (10
    hours)</p>
    <p><input name="Custom_De sign" type="radio" />&nbsp; I would
    like a custom design created for my site.&nbsp; (20
    hours)&nbsp;</p>
    </fieldset>
    <fieldset name="Other Graphics">
    <legend class="alignlef t">Other Graphics</legend>
    <p><input name="Need_Cust om_Graphics" type="checkbox" />&nbsp; I
    need some custom graphics made.&nbsp; (4 hours)</p>
    <p><input name="Mouse-over_Graphics" type="checkbox" />&nbsp; I
    need graphic mouse-over buttons.&nbsp; (4 hours)</p>
    <p><input name="Few_Stock " type="checkbox" />&nbsp;&nbsp; I
    need a few stock photographs integrated.&nbs p; (4 hours)</p>
    <p><input name="More_Stoc k" type="checkbox" />&nbsp;&nbsp; I
    need several stock photographs integrated.&nbs p; (9
    hours)</p>
    </fieldset>
    <fieldset name="Flash">
    <legend class="alignlef t">Flash</legend>
    <p><input name="Flash_Men u" type="checkbox" />&nbsp; I
    need a flash menu.&nbsp; (6 hours)</p>
    <p><input name="Flash_Ani mation" type="checkbox" />&nbsp;&nbsp; I
    need a short custom flash animation.&nbsp ; (3 hours)</p>
    <p><input name="Total_Fla sh" type="checkbox" />&nbsp;&nbsp; I
    want my site in Flash for a total of&nbsp;
    <select name="Select1">
    <option></option>
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    <option>6</option>
    <option>7</option>
    <option>8</option>
    </select>&nbsp; pages.&nbsp; (5 hours per page.)</p>
    <p><input name="Flash_Ban ner" type="checkbox" />&nbsp;&nbsp; I
    need a flash banner.&nbsp; (4 hours)</p>
    </fieldset>
    <fieldset name="Content">
    <legend class="alignlef t">Content</legend>
    <p>
    <input name="I_add_Con tent" type="radio" checked="checke d" />&nbsp;
    I will add my content with a content manager.&nbsp; (0
    hours)</p>
    <p><input name="Content_P ages" type="radio" />&nbsp;&nbsp; I will
    supply <select name="Select2">
    <option></option>
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    <option>6</option>
    <option>7</option>
    <option>8</option>
    <option>9</option>
    <option>10</option>
    </select> pages of content in MS Word or Notepad text.&nbsp;
    (3 hours per page)</p>
    <p><input name="Copyright ing_Pages" type="checkbox" />&nbsp; I need
    <select name="Select3">
    <option></option>
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    <option>6</option>
    <option>7</option>
    <option>8</option>
    <option>9</option>
    <option>10</option>
    </select> pages of copywriting done for my content.&nbsp;
    (5 hours per page.<br /></p>
    </fieldset>
    <fieldset name="Public Features">
    <legend class="alignlef t">Public Features</legend>
    <p><input name="Member_Re gistration" type="checkbox" />&nbsp;
    Member Registration&nb sp; (6 hours)</p>
    <p><input name="Discussio n_Forum" type="checkbox" />&nbsp;&nbsp;
    Discussion Forum&nbsp; (5 hours)</p>
    <p><input name="Contact_F orm" type="checkbox" />&nbsp;
    Contact Form&nbsp; ( 3 hours)</p>
    <p><input name="Links_Pag e" type="checkbox" />&nbsp;
    Links Page&nbsp; (3 hours)</p>
    <p><input name="Site_Sear ch" type="checkbox" />&nbsp;
    Site Search&nbsp; (4 hours)</p>
    <p><input name="Auto-Responder" type="checkbox" />&nbsp;
    Email Auto-responder (2 hours)</p>
    <p><input name="File_Uplo ad" type="checkbox" />&nbsp;
    File upload ( 8 hours)</p>
    </fieldset>
    <fieldset name="Ecommerce ">
    <legend class="alignlef t">Ecommerce </legend>
    <p><input name="Simple_Ca rt" type="checkbox" />&nbsp;
    Simple shopping cart&nbsp; (5 hours)</p>
    <p><input name="Database_ Cart" type="checkbox" />&nbsp;
    Database shopping cart&nbsp; (10 hours)</p>
    <p><input name="Credit_Ca rd" type="checkbox" />&nbsp;
    Credit Card Processing&nbsp ; ( 4 hours)</p>
    <p><input name="PayPal" type="checkbox" />&nbsp;
    PayPal&nbsp; processing</p>
    </fieldset>
    <fieldset name="Admin_Fea tures">
    <legend class="alignlef t">Admin Features</legend>
    <p><input name="Blog" type="checkbox" />&nbsp; Off
    the shelf Blog&nbsp; (3 hours)</p>
    <p><input name="Custom_Bl og" type="checkbox" />&nbsp;
    Custom Site Blog&nbsp; (6 hours)</p>
    <p><input name="Photo_Gal lery" type="checkbox" />&nbsp;
    Photo Gallery&nbsp; (6 hours)</p>
    <p><input name="Member_Ad min" type="checkbox" />&nbsp;
    Member Administration& nbsp; (5 hours)</p>
    <p><input name="Site_Stat istics" type="checkbox" />&nbsp;
    Site Statistics (1 hour)</p>
    </fieldset>
    <fieldset name="SEO">
    <legend class="alignlef t">SEO</legend>
    <p><input name="MetaTag" type="checkbox" />&nbsp;
    MetaTag Keyword Optimization (5 hours)</p>
    <p><input name="Search_En gine_Submission " type="checkbox" />&nbsp;
    Search Engine Submission (3 hours)</p>
    <p><input name="Link_Buil ding" type="checkbox" />&nbsp;
    Minor Link Building (6 hours)</p>
    </fieldset>

    <br />
    <input name="Calculate _Cost" type="button" value="Calculat e Cost" /></form>[/HTML]
    Last edited by acoder; Aug 19 '08, 12:06 PM. Reason: Added [code] tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Have you managed anything so far?

    What I suggest you do is name the radio buttons with the same name for each section. That way you can access all of them in one go and then loop over them. Alternatively, use document.getEle mentsByTagName( "input") to get all of the input elements on the page. Also add value attributes for each radio button that contains the hours figure. That would make it easier to add up the values.

    Comment

    Working...