ASP and JavaScript (Passing parameter)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • F159753
    New Member
    • Apr 2008
    • 31

    ASP and JavaScript (Passing parameter)

    Hello,

    I have a form includes one text box named "Date", one Submit botton named " Add Item" which will submit the form and open other form.

    there is onemore button named " Add Mileage" which by pushing that, I would like to check if the text box named " Date" is empty or not and in both case will open other window and depends if the text box is empty or not, shows different messages in new window open up.

    Please please please let me know if you have any solution.

    Best Regards,
    Faranak
  • jeffstl
    Recognized Expert Contributor
    • Feb 2008
    • 432

    #2
    Originally posted by F159753
    Hello,

    I have a form includes one text box named "Date", one Submit botton named " Add Item" which will submit the form and open other form.

    there is onemore button named " Add Mileage" which by pushing that, I would like to check if the text box named " Date" is empty or not and in both case will open other window and depends if the text box is empty or not, shows different messages in new window open up.

    Please please please let me know if you have any solution.

    Best Regards,
    Faranak

    If you are going to submit the form either way and open a new window either way, you probably one need 1 button right? If you are talking about alert boxes like a validation of a form before submission, then yes you will need to use javascript or client side vbscript.

    A perfect example of this can be found here


    If you are going to submit the form though you can just use ASP to check the value

    Code:
    dim UserDate
    UserDate = request.form("txtDate")
    if UserDate = "" then
         'determine message string
    else
         'they entered the date
    end if

    Comment

    • F159753
      New Member
      • Apr 2008
      • 31

      #3
      Thanks for your reponse, but It is not clear to me yet. Here is my code:



      <form name="Formd" action="Contrac torExpenseAddIt em.asp" method="post" >

      <input name="WeekEndin gDate" ID="WeekEndingD ate" type="text">


      <td colspan="1" valign="top"><s pan class="text"><i nput type="submit" value="Add Item >"> </span></td>


      <td colspan="1" valign="top" width="200"><in put type="button" onClick=window. open('Contracto rExpenseAddMile age.asp?IID=<%= A%>','AddMileag eWindow','width =600,height=250 ,toolbar=yes,lo cation=yes,dire ctories=yes,sta tus=yes,scrollb ars=yes,copyhis tory=yes,resiza ble=yes') value="Add Mileage >"></td>

      </form>

      As you see, by Submitting "Add Item" in form action I am submitting the form and opening other form.
      My problem is with other button named " Add Mileage" when I click on the button I want to validate the text box first then open other window so basically my form is not submitting so I can't request.form the text box value!!!!!

      What should I do? :(

      Comment

      • jeffstl
        Recognized Expert Contributor
        • Feb 2008
        • 432

        #4
        Originally posted by F159753
        Thanks for your reponse, but It is not clear to me yet. Here is my code:



        <form name="Formd" action="Contrac torExpenseAddIt em.asp" method="post" >

        <input name="WeekEndin gDate" ID="WeekEndingD ate" type="text">


        <td colspan="1" valign="top"><s pan class="text"><i nput type="submit" value="Add Item >"> </span></td>


        <td colspan="1" valign="top" width="200"><in put type="button" onClick=window. open('Contracto rExpenseAddMile age.asp?IID=<%= A%>','AddMileag eWindow','width =600,height=250 ,toolbar=yes,lo cation=yes,dire ctories=yes,sta tus=yes,scrollb ars=yes,copyhis tory=yes,resiza ble=yes') value="Add Mileage >"></td>

        </form>

        As you see, by Submitting "Add Item" in form action I am submitting the form and opening other form.
        My problem is with other button named " Add Mileage" when I click on the button I want to validate the text box first then open other window so basically my form is not submitting so I can't request.form the text box value!!!!!

        What should I do? :(
        Well it all depends on what you require of the behavior of the app.

        You can't have it both ways. You either need to validate the form prior to submission, (i.e don't let them submit unless the form is correct) or you need to go ahead and let them submit the form, and do your checking on the other side with the request.form like above.

        Either way you really only need 1 button. Then you just need to call your validating javascript from the onsubmit event of the form, like was displayed in the above example link.

        [code=javascript]
        <script type="text/javascript">
        function validate_requir ed(field,alertt xt)
        {
        with (field)
        {
        if (value==null||v alue=="")
        {alert(alerttxt );return false;}
        else {return true}
        }
        }function validate_form(t hisform)
        {
        with (thisform)
        {
        if (validate_requi red(email,"Emai l must be filled out!")==false)
        {email.focus(); return false;}
        }
        }
        </script>
        [/code]

        Code:
        <form action="nextwindow.asp"
        onsubmit="return validate_form(this)"
        method="post">
        I guess if this still doesn't answer your question please provide more info on exactly what you are trying to accomplish. Are you trying to do a calculation for the user before he proceeds to the final window? Or are you trying to actually do a validation before the user submits?

        Again I must say that if you are wanting them to submit the form either way then just use your request.form method on the next page to check the value and display your messages then.

        I do think I see what you are trying to do. You are trying to bring up a popup window with information on it if they submit the form a certain way (with the value entered)? If so you can just do a pop up window on the body onload event on the ContractorExpen seAddItem.asp page, that will get its info from the request.form data.

        All kind of guesses though since I'm not sure what your final goal is here.

        Comment

        • F159753
          New Member
          • Apr 2008
          • 31

          #5
          Thanks a bunch.

          how should I complete the following code:

          onClick="javasc ript:window.ope n('abc.asp'

          if I want to send a parameter with it without submitting the form?

          It should be something like the following line, but it is not right!!!

          onClick="javasc ript:window.ope n( 'ContractorExpe nseAddMileage.a sp?A=) + escape(document .theForm.userNa me.value)"

          Thanks

          Comment

          • F159753
            New Member
            • Apr 2008
            • 31

            #6
            oh Jeff,
            Thank you soooooooooooooo ooooooo much. I could write the correct line and it is working :)

            <input type="button" value="Add Mileage >" onClick="javasc ript:window.ope n( 'ContractorExpe nseAddMileage.a sp?WED=' + escape(document .Formd.WeekEndi ngDate.value))" />

            Thanks
            Faranak

            Comment

            • jeffstl
              Recognized Expert Contributor
              • Feb 2008
              • 432

              #7
              Originally posted by F159753
              oh Jeff,
              Thank you soooooooooooooo ooooooo much. I could write the correct line and it is working :)

              <input type="button" value="Add Mileage >" onClick="javasc ript:window.ope n( 'ContractorExpe nseAddMileage.a sp?WED=' + escape(document .Formd.WeekEndi ngDate.value))" />

              Thanks
              Faranak
              Excellent!

              Glad I could help

              Comment

              Working...