Web Analytics Made Easy -
StatCounter help with jv script - CodingForum

Announcement

Collapse
No announcement yet.

help with jv script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • help with jv script

    Hi All,

    For some reason below script doesn't want to work. Please can you suggest why.

    function send()
    {
    i = 7;
    subject = document.email_us.elements[i];
    {
    f = document.getElementById('email_us');
    err = new Error();
    if (isempty(f.subject)) err.add('Subject is mandatory. Please re-enter.');

    if (err.isset()){
    err.show();
    return false;
    }

    return true;
    }

    ---

    The reason I am assigning subject = document.email_us.elements[i]; is the actual text box name of the subject is 0012xo and I can't change that name. At the same time i need to make sure that it is not empty.

    Thanks in advance....

    Regards,

  • #2
    Riddled with errors.

    i = 7; // what is this supposed to do?

    {
    f = document.getElementById('email_us');

    err = new Error(); // only used where runtime errors are encountered.

    if (err.isset()){
    err.show();


    I am guessing that you want:-

    Code:
    function send() { 
    var subject = document.email_us.elements[i]; 
    if (subject.value = "") {  // empty field 
    alert ('Subject is mandatory. Please re-enter.'); 
    return false;
    } 
    return true;
    }

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

    Comment


    • #3
      Thanks

      Hi there,

      Many thanks for your reply. But I am afraid it doesn't work - produced no error as well.

      If I can explain to you again, I would like to check whether subject field has been filled in.

      Here is the form:

      <form id="email_us" action="https://www.mysite.com" method="POST">
      <table width="90%" border="0" cellpadding="0" cellspacing="0">
      <tr>
      <td class="label">Title</td>
      </tr>
      <tr>
      <td class="label">
      <input id="title" name="title" size="3" type="text" />
      </td>
      </tr>
      <tr>
      <td class="label">Subject</td>
      <td><input id="00N80000002wFEw" maxlength="25" name="00N80000002wFEw" size="20" type="text" /></td>
      </tr>
      <tr>
      <td colspan="2" style="text-align: right;"><input type="button" value="Send" onclick="send()" /></td>
      </tr>
      </table>
      </form>

      ----

      I can check other fields all right but this subject field is a bit funny for my normal validation routine.

      Thanks,

      Comment


      • #4
        But I am afraid it doesn't work - produced no error as well.
        No, it does work. I do not post scripts that do not work. Your problem is that you have not given your form a name:-

        <form name = email_us" id="email_us"

        Then the validation script should look like:-

        Code:
        <script type = "text/javascript">
        function send() { 
        var subject = document.email_us.elements[1].value; 
        subject = subject.replace(/^\s+|\s+$/g,"");  // strip leading and trailing spaces [COLOR="Blue"]OR[/COLOR]
        subject = subject.replace(/[^A-Z0-9]/gi,"");  // strip all non-alphanumeric characters if desired
        if (subject.length < 4) {  // fewer than 4 characters remaining in field  
        alert ('Subject is mandatory. Please re-enter.'); 
        document.email_us.elements[1].focus();
        return false;
        } 
        return true;  // default so not required
        }
        
        </script>
        But an id should not properly start with a number.
        Last edited by Philip M; Apr 16, 2009, 12:54 PM.

        All the code given in this post has been tested and is intended to address the question asked.
        Unless stated otherwise it is not just a demonstration.

        Comment


        • #5
          Thanks Phil.

          It worked perfectly.

          Thanks,

          Comment

          Working...
          X