SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Hybrid View

  1. #1
    SitePoint Evangelist kashaziz's Avatar
    Join Date
    Feb 2001
    Location
    PK
    Posts
    460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I require java script to check characters typed including white spaces in a text area. I am using the form in a cold fusion file. I have tried a function that checks onsubmit of the form but is not working. Please help

    kashaziz@yahoo.com

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2001
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do you mean a common validation method?

    ie

    Code:
    <script language="javascript">
    
    function checkdis(){
      if (document.formName.fieldName.value.indexOf(" ")!=-1){
    
           alert("Sorry, you have a space.");
           document.formName.fieldName.focus();return false
      } 	
    }
    
    </script>
    then in your form:

    Code:
    <form name="formName" onSubmit="return checkdis()";>
      <input type="text" name="fieldName"><br>
      <input type="submit" name="submit">
    </form>

  3. #3
    SitePoint Evangelist kashaziz's Avatar
    Join Date
    Feb 2001
    Location
    PK
    Posts
    460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have used a mehtod like that but its not working

  4. #4
    I believe you have my stapler. scrubz's Avatar
    Join Date
    Feb 2001
    Location
    Van down by the river
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, what isn't working? And what exactly are you checking for? More details would be helpful. Help us help you.

  5. #5
    SitePoint Evangelist kashaziz's Avatar
    Join Date
    Feb 2001
    Location
    PK
    Posts
    460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here is the code:

    <html>
    <head>
    <SCRIPT LANGUAGE="JavaScript">

    <!-- This script and many more are available free online at -->
    <!-- The JavaScript Source!! http://javascript.internet.com -->

    <!-- Begin
    function checkchars(form) {
    var max=15;
    if (form.chars.value.length > max) {
    alert("Please do not enter more than 15 characters. Please shorten your entry and submit again.");
    return false;
    }
    else return true;
    }
    // End -->
    </script>

    </head>
    <body>
    <cfif isdefined("form.jobobj") and form.jobobj is not "">
    <cfoutput>#form.jobobj# <br></cfoutput>
    <cfelse>
    <form action="test.cfm" method="post" onsubmit="return checkchars(this)">
    <textarea name="jobobj" wrap="ON" cols="50" rows="5" wrap="virtual" ></textarea>
    <input type="submit" name="submit" value="submit">
    </form>
    </cfif>
    </body>
    </html>

  6. #6
    I believe you have my stapler. scrubz's Avatar
    Join Date
    Feb 2001
    Location
    Van down by the river
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change the name of the parameter that your function is using (form) to frm, or something else.

    function checkchars(frm) {
    var max=15;
    if (frm.chars.value.length > max) {
    alert("Please do not enter more than 15 characters. Please shorten your entry and submit again.");
    return false;
    }
    else return true;
    }

    And although it works without it, I'd give your form a name in the form tag.

    <form name="myForm" action="test.cfm" method="post" onsubmit="return checkchars(this)">

  7. #7
    SitePoint Evangelist kashaziz's Avatar
    Join Date
    Feb 2001
    Location
    PK
    Posts
    460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    still its not working

  8. #8
    SitePoint Enthusiast
    Join Date
    Jan 2001
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <SCRIPT LANGUAGE="JavaScript">

    <!-- This script and many more are available free online at -->
    <!-- The JavaScript Source!! http://javascript.internet.com -->

    <!-- Begin
    function checkchars() {
    var max=15;
    if (document.formName.jobobj.value.length > max) {
    alert("Please do not enter more than 15 characters. Please shorten your entry and submit again.");
    return false;
    }
    else return true;
    }
    // End -->
    </script>

    </head>
    <body>
    <cfif isdefined("form.jobobj") and form.jobobj is not "">
    <cfoutput>#formName.jobobj# <br></cfoutput>
    <cfelse>
    <form name="formName" onsubmit="return checkchars(this)">
    <textarea name="jobobj" wrap="ON" cols="50" rows="5" wrap="virtual" ></textarea>
    <input type="submit" name="submit" value="submit">
    </form>
    </cfif>
    </body>
    </html>

  9. #9
    SitePoint Enthusiast
    Join Date
    Jan 2001
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the javascript should now work anyway

  10. #10
    SitePoint Evangelist kashaziz's Avatar
    Join Date
    Feb 2001
    Location
    PK
    Posts
    460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks its working


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
  •