SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2003
    0 Post(s)
    0 Thread(s)

    Question Can Someone Please Help Me

    I am new to this so someone PLEASE HELP ME!!

    I have a php form which I am trying to check. My code is shown below (only the piece which is questionable). This code works, however, what I want is the line I currently have commented off. If I comment off the first "if" statement (the one I don't want) I get an error saying "Object Expected". What am I doing wrong? Why will it work for the first if statement but not the second?

    <script language="JavaScript" type="text/javascript">
    function checkform (form1)
    {if (form1.txtJobNo.value == "C"){
    //{if (preg_match("/[A-a]{2,2}[0-9]{8,8}/", form1.$jobno)){
    alert ("Please enter a valid job number");
    return False;}

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Dallas, TX
    0 Post(s)
    0 Thread(s)
    preg_match is a PHP function, and doesn't exist in javascript. Try this instead

    { if ( /[A-a]{2,2}[0-9]{8,8}/.test( form1.$jobno ) ) {

    although, I must say, that's one of the oddest patterns I've seen.

    What is $jobno supposed to be? That will likely cause problems too, as JS properties can't start with anything but a-z and the underscore.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts