Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    rewrite VBscript to javascript

    I am working on another rewrite. Can use some help as I am stuck like always. Thank you very much ahead of time!

    Code:
    <SCRIPT language="VBScript">
    function doMySubmit(frmID)
    msgbox("Hello there")
    <%if mDoNotSubmit = "" then%>
    msgbox("Hello there doSubmit")
      doSubmit(frmID)
    <%else%>
    msgbox("Hello check the doSubmit")
      if doSubmit(frmID) then ' got by the form validation routines, now see how the appraisal is going
    msgbox("Hello checking the doSubmit was successful")
        For x = 0 to document.all(frmID).length - 1
          set thisItem = document.all(frmID).elements(x)
          if thisItem.name = "mDRIVEABLE" then
            if ThisItem.checked then
              mChecked = true
            else
              mChecked = false
            end if
            Exit for
          end if
        next
        if mChecked then
          document.all(frmID).submit()
        else
          mFail = false
          For x = 0 to document.all(frmID).length - 1
            set thisItem = document.all(frmID).elements(x)
            if thisItem.name = "Veh_Location" then
              if thisItem.value = "" then
                mFail = true
              end if
            elseif thisItem.name = "VEH_ADDRESS" then
              if thisItem.value = "" then
                mFail = true
              end if
            elseif thisItem.name = "VEH_CITY" then
              if thisItem.value = "" then
                mFail = true
              end if
            elseif thisItem.name = "VEH_STATE" then
              if thisItem.selectedIndex < 0then
                mFail = true
              end if
            elseif thisItem.name = "VEH_ZIP" then
              if thisItem.value = "" then
                mFail = true
              end if
            elseif thisItem.name = "VEH_PHONE" then
              if thisItem.value = "" then
                mFail = true
              end if
            end if
          next
          if mFail then
            alert("You must check the driveable box, or fill in all information in the Location section")
          else
            document.all(frmID).submit()
          end if
        end if
      end if
    <%end if%>
    end function
    </SCRIPT>

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Ummm...you have both client side *AND* server side (ASP) VBScript in there.

    But that client side VBS may be some of the worst I have ever seen.

    WHY would you do UTTER JUNK like this:
    Code:
        For x = 0 to document.all(frmID).length - 1
          set thisItem = document.all(frmID).elements(x)
          if thisItem.name = "mDRIVEABLE" then
            if ThisItem.checked then
              mChecked = true
            else
              mChecked = false
            end if
            Exit for
          end if
        next
    *SEARCHING* for mDRIVEABLE instead of simply doing
    Code:
        mChecked = document.all(frmID).mDRIVEABLE.checked
    Sheesh. What a total mess.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    *AT A GUESS* this is what you need:
    Code:
    <script type="text/javascript">
    <%
    if mDoNotSubmit = "" then
    %>
    function doMySubmit(frmID)
    {
        alert("mDoNotSubmit was blank, so no appraisal checking");
        doSubmit(frmID)
    }
    <%else%>
    function doMySubmit(frmID)
    {
        alert("we will do appraisal checking");
        if doSubmit(frmID)
        {
            // got by the form validation routines, now see how the appraisal is going
            alert( "checking the doSubmit was successful");
            var form = document.getElementById(frmID);
            
            if ( form.mDRIVEABLE.checked )
            {
                form.submit();
                return;
            }
            
            if (    form.Veh_Location.value.length < 6 
                 || form.VEH_ADDRESS.value.length < 6 
                 || form.VEH_CITY.value.length < 4 
                 || form.VEH_ADDRESS.value.length < 6 
                 || form.VEH_STATE.value.length < 2 
                 || form.VEH_ZIP.value.length < 5
                 || form.VEH_PHONE.value.length < 10
            ) {
                alert("You must check the driveable box, or fill in all information in the Location section");
                return;
            }
            form.submit();
        }
    }
    <%end if%>
    </script>
    But CAUTION: VBScript will allow you do use form.VEH_ADDRESS even if the field in the <form> is actually <input name="veh_address">.

    That is, VBS is *NOT* case-sensitive. JavaScript *is*. So make sure that the spellings of all those form field names is *EXACTLY* correct, upper/lower case and all.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    eugene.garan (06-19-2013)

  • #4
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Yes, I totally agree. The code is around 10 years old and it has been modified over the years. The entire program consists of so much mess, html, vb script and java script all built pages within pages. design and programming code on top of each other within pages, all built on mostly tables.. it is a huge mess... that is why I am back in the forum everyday asking for help ... but thank you very much you have been an awesome help for me!! A+++


  •  

    Posting Permissions

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