onsubmit two functions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oll3i
    Contributor
    • Mar 2007
    • 679

    onsubmit two functions

    I want to call two functions on submit
    onsubmit="retur n checkTitle(this ,'<? echo $language?>');s etOfferCookies( )"
    but it doesnt even call the first function

    [code=javascript]
    function checkTitle(form ,language){
    alert("checkTit le");<----to check if it works
    if(form.title.v alue.length==0 || form.title.valu e=="***Proszę wpisać tytuł!" || form.title.valu e=="***Please enter the title!" ){
    document.getEle mentById("title ").style.color= "red";
    if(language=="p olish"){
    form.title.valu e="***Proszę wpisać tytuł!";}
    else {form.title.val ue="***Please enter the title!";}
    return false;
    }else {document.getEl ementById("titl e").style.color ="black";}
    return true;
    }
    [/code]

    thank You
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Originally posted by oll3i
    I want to call two functions on submit
    onsubmit="retur n checkTitle(this ,'<? echo $language?>');s etOfferCookies( )"
    When you had already returned, second function could never execute.

    Try this...
    Code:
    onsubmit="setOfferCookies(); return checkTitle(this,'<? echo $language?>');"
    Last edited by hsriat; Mar 7 '08, 06:17 PM. Reason: tags

    Comment

    • oll3i
      Contributor
      • Mar 2007
      • 679

      #3
      but i dont want this second function to execute when the first function returns false
      the problem is that the first function doesnt execute
      that's why i added the alert box to see if it executes and the alert box doesnt show?

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        As far as the first function is concerned, I remember you asked this earlier too.
        Wasn't that solved that time?

        Comment

        • hsriat
          Recognized Expert Top Contributor
          • Jan 2008
          • 1653

          #5
          Originally posted by oll3i
          but i dont want this second function to execute when the first function returns false
          the problem is that the first function doesnt execute
          that's why i added the alert box to see if it executes and the alert box doesnt show?
          The way use have used it, it won't get executed even if the first function returns true.
          For that, use this:
          Code:
          onsubmit="if (checkTitle(this,'<? echo $language?>')) { setOfferCookies(); return true;} else {return false;}"

          Comment

          • oll3i
            Contributor
            • Mar 2007
            • 679

            #6
            thank you
            the problem with the first function is that it doesnt even execute

            Comment

            • hsriat
              Recognized Expert Top Contributor
              • Jan 2008
              • 1653

              #7
              Originally posted by oll3i
              thank you
              the problem with the first function is that it doesnt even execute
              Can you show me the source (the one you get when you click on view source) of your page that displays the form and the above function.

              Comment

              • oll3i
                Contributor
                • Mar 2007
                • 679

                #8
                <form name="editor" action="save.ph p?language=poli sh" onsubmit="if (checkTitle(thi s,'polish')) { setOfferCookies (); return true;} else {return false;}">
                <table width="720" border="0" cellspacing="0" cellpadding="2" >
                <tr>
                <td width="180">
                <span id="profile_fon t_weight">
                Tytuł*
                </span>
                </td>
                <td>
                <input type="text" size="101" name="title" id="title">
                </td>
                </tr>

                js is included in the head

                Comment

                • hsriat
                  Recognized Expert Top Contributor
                  • Jan 2008
                  • 1653

                  #9
                  [html]<script>
                  function checkTitle(form ,language) {
                  alert("checkTit le");//<----to check if it works
                  if (form.title.val ue.length==0 || form.title.valu e=="***Prosze wpisac tytul!" || form.title.valu e=="***Please enter the title!" ) {
                  document.getEle mentById("title ").style.color= "red";
                  if(language=="p olish") form.title.valu e="***Prosze wpisac tytul!";
                  else form.title.valu e="***Please enter the title!";
                  return false;
                  }
                  else {
                  document.getEle mentById("title ").style.color= "black";
                  }
                  return true;
                  }
                  </script>
                  <form name="editor" action="save.ph p?language=poli sh" onsubmit="if (checkTitle(thi s,'polish')) { setOfferCookies (); return true;} else {return false;}">
                  <table width="720" border="0" cellspacing="0" cellpadding="2" >
                  <tr>
                  <td width="180">
                  <span id="profile_fon t_weight">
                  Tytul*
                  </span>
                  </td>
                  <td>
                  <input type="text" size="101" name="title" id="title">
                  <!--just added the submit button-->
                  <input type="submit" name="Submit" value="Submit">
                  </td>
                  </tr>
                  </table>[/html]I tried this, and it worked.
                  There's nothing wrong with the JavaScript code.

                  Comment

                  • oll3i
                    Contributor
                    • Mar 2007
                    • 679

                    #10
                    You wont believe it i forgot to end the form hihi now it works

                    Comment

                    • hsriat
                      Recognized Expert Top Contributor
                      • Jan 2008
                      • 1653

                      #11
                      Originally posted by oll3i
                      You wont believe it i forgot to end the form hihi now it works
                      No, that's not the case, I would believe that.

                      Glad to know it works. :)

                      Harpreet

                      Comment

                      Working...