SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    submitted a form with javascript (based on variable)

    I want to use Javascript to submit one of two forms,

    "myform" and "myotherform"

    If the value of TotalMinutes is greater then 0, I want to submit MyOtherForm, if it is 0(empty), I want to submit MyForm

    The code I am using:

    <script language="javascript">
    totalMinutes = 0;

    function calculateTotalMinutes(thisCheckbox){
    if (thisCheckbox.checked)
    {
    totalMinutes += parseFloat(thisCheckbox.value);
    } else {
    totalMinutes -= parseFloat(thisCheckbox.value);
    }
    document.getElementById("totalMinutes").value = totalMinutes;
    document.getElementById("totalMinutes2").value = totalMinutes;
    }
    </script>

    <script type="text/javascript">
    function submitform()
    {
    document.DETERMINE-WHICH-FORM?.submit();
    }
    </script>

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,683
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by listenmirndt View Post
    I want to use Javascript to submit one of two forms,

    "myform" and "myotherform"
    Once you've defined the variables, you could just do something like:

    Code javascript:
    (totalMinutes > 0)
        ? myOtherForm.submit()
        : myForm.submit();
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •