problom with javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shashikant dubey
    New Member
    • Oct 2007
    • 1

    #1

    problom with javascript

    i am doing validation thru javascript
    for this i have written a function in(form1.aspx) javascript like this

    function checkfield(myfo rm)
    {
    var myform=document .forms[0];
    ok=true
    if(myform.txtna me.text=="")
    {
    alert("Please Enter Your FirstName.")
    myform.txtname. focus()
    ok=false
    break;
    }
    if(myform.txtad dress.text=="")
    {
    alert("Please Enter Your lastName.")
    myform.txtaddre ss.focus()
    ok=false
    break;
    }
    and i am calling this from form(form1.aspx .cs) like this

    Button1.Attribu tes.Add("onclic k", "return checkfield(form 1);");

    so what is happening , without completing the field it is getiing inserted in database for this i have written code,pls help me.

    waitning ur reply
    shashikant
  • KnightHack
    New Member
    • Oct 2007
    • 15

    #2
    U try this if(myform.txtna me.text==' ')

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by shashikant dubey
      i am doing validation thru javascript
      for this i have written a function in(form1.aspx) javascript like this

      function checkfield(myfo rm)
      {
      var myform=document .forms[0];
      ok=true
      if(myform.txtna me.text=="")
      {
      alert("Please Enter Your FirstName.")
      myform.txtname. focus()
      ok=false
      break;
      }
      if(myform.txtad dress.text=="")
      {
      alert("Please Enter Your lastName.")
      myform.txtaddre ss.focus()
      ok=false
      break;
      }
      and i am calling this from form(form1.aspx .cs) like this

      Button1.Attribu tes.Add("onclic k", "return checkfield(form 1);");

      so what is happening , without completing the field it is getiing inserted in database for this i have written code,pls help me.

      waitning ur reply
      shashikant
      How are you calling the function?
      Did you put an alert at the first line to check that your function is being called at all?

      Comment

      • sreemathy2000
        New Member
        • Oct 2007
        • 40

        #4
        In are not to fix the problem with the JavaScripts, the same functionality can be done by using the Validation Controls. There is conrol called 'RequiredFiledv alidator' in the Toolbox.
        Hope it helps!

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          Why are you creating two varaibles with the same name in your function?

          You pass in "myform" then create a var called "myform"
          [code=javascript]
          function checkfield(myfo rm)
          {
          var myform=document .forms[0];
          [/code]

          Comment

          Working...