DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 15 of 15

Thread: easy one

  1. #1
    Join Date
    Mar 2007
    Posts
    61

    easy one

    What is wrong with this statment.
    Code:
    function validate() {
      var Sign = document.getElementById('Sign');
      if(Sign.value = 'Enter Your ID Number'){
        alert('Please sign the form by inputing your badge number');
        return false;
      }
      return true;
    }
    I get the alert when it is true or false and I cannot sumit it. any ideas.

  2. #2
    Join Date
    Sep 2007
    Posts
    37
    Sign.value = 'Enter Your ID Number'
    Replace = with ==

  3. #3
    Join Date
    Mar 2007
    Posts
    61
    Thanks its still giving me problems. when I hit submit it still give me the messgae but it still submit it. I want it to not submit if it is not changed whta am I missing
    Code:
    <input type="Submit" value="Submit" onSubmit="validate()"/>

  4. #4
    Join Date
    Jul 2007
    Location
    Minnesota
    Posts
    155
    Your statement allows return true even when the condition is false.
    Note that I have added the else to the code.
    Try and see if this helps.
    Code:
    function validate() 
    {
      var Sign = document.getElementById('Sign');
      if(Sign.value = 'Enter Your ID Number')
    {
        alert('Please sign the form by inputing your badge number');
        return false;
      }
    else
    {
      return true;
    }
    }

  5. #5
    Join Date
    Sep 2007
    Posts
    37
    Quote Originally Posted by landslide
    Code:
    <input type="Submit" value="Submit" onSubmit="validate()"/>
    Put ; after calling function.
    Code:
    <input type="Submit" value="Submit" onSubmit="validate();"/>

  6. #6
    Join Date
    Mar 2007
    Posts
    61
    I have done all of this but it still sows the message and it still updates the information even if it is lank any oter ideas

  7. #7
    Join Date
    Jul 2007
    Location
    Minnesota
    Posts
    155
    Could you post your entire form code here?
    It is only fair that in order to help you, it is good to show what exactly you are doing.
    That way, the correction can be done properly.

  8. #8
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,651
    Quote Originally Posted by Emefa
    Could you post your entire form code here?
    Also, state what the code is doing, and what the code should be doing.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  9. #9
    Join Date
    Jan 2005
    Posts
    413
    If you use a return in the function you must use return in the call.

    onSubmit="return validate()"/>

  10. #10
    Join Date
    Mar 2007
    Posts
    61
    That above is my code Ill post it again if you like. It Still doesnt work arrgg

    Code:
    <script type="text/javascript" language="JavaScript">
    function validate() 
    {
      var Sign = document.getElementById('Sign');
      if(Sign.value = 'Enter Your ID Number')
    {
        alert('Please sign the form by inputing your badge number');
        return false;
      }
    else
    {
      return true;
    }
    }
    </script>
    <input type="Submit" value="Submit" onSubmit="return validate()"/>:confused:

  11. #11
    Join Date
    Jan 2005
    Posts
    413
    I should've looked more closely at the code. onSubmit="return validate()"/ belongs inside the form tag, not the button tag.

  12. #12
    Join Date
    Mar 2007
    Posts
    61
    I changed the code to have the validate where the form tag is. Now it will not let me submit not matter what it gives me the message and wont submit. I have attached all my form code.
    Code:
    <form id="form1" name="form1" method="POST" action="<%=MM_editAction%>" onSubmit="return validate()">
      <table width="700" border="1" align="center">
        <tr>
          <td bgcolor="009999"><div align="center"><span class="style32">Will the employee have enough
              leave to cover the requests?</span> Yes
              <input name="Yesaccurate" type="checkbox" id="Yesaccurate" value="Yes is accruate" />
            No
            <input name="Noaccurate" type="checkbox" id="Noaccurate" onclick="alert(&quot;Please list what leave is not approved below&quot;)" value="No" />
          </div>
            <label>
            <div align="center"></div>
            </label></td>
        </tr>
        <tr>
          <td bgcolor="009999"><div align="center"><span class="style39"><strong>All leave can be approved
            with the following exceptions: </strong></span>
            <textarea name="Reason1" cols="80" id="Reason1">None</textarea>
          </div></td>
        </tr>
        <tr>
          <td bgcolor="009999"><div align="center">Manager's Verification* Signature
          </div>
            <label>
            <div align="center">
              <input name="Sign" type="text" class="style25" id="Sign" value="Enter Your ID Number" />
            </div>
          </label></td>
        </tr>
    Code:
     <input type="Submit" value="Submit"/>

  13. #13
    Join Date
    Jan 2005
    Posts
    413
    Have you correct this yet? if(Sign.value = 'Enter Your ID Number')

    should be

    if(Sign.value == 'Enter Your ID Number')

  14. #14
    Join Date
    Mar 2007
    Posts
    61
    I am so sorry for not responding It has been crazy. I will try this tomorrow. Thanks you so much for replying.

  15. #15
    Join Date
    Mar 2007
    Posts
    61
    That worked thanks again

Similar Threads

  1. Easy Discussion.NET download available
    By Abdul Meraj in forum dotnet.announcements
    Replies: 0
    Last Post: 06-01-2002, 04:34 PM
  2. Replies: 84
    Last Post: 01-29-2001, 01:12 PM

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
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links