Login - javascript execution

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kerriejones
    New Member
    • Mar 2007
    • 8

    Login - javascript execution

    I am trying to create a simple login routine, and am failing completely, I have tried to simplify the test and still no luck.

    HTML
    <form method="post" action="" >
    <div>
    <input type="text" name="field1"/>
    <input type="password" name="field2"/>
    <input type="button" name="submit" value="Click" onclick="javasc ript:test(field 1.value,field2. value)"/>
    </div>
    </form>

    SCRIPT
    <script type="javascrip t">
    <!--
    function test(field1,fie ld2)
    {
    echo "in the test<br>";
    alert ("i am in the code");
    return;
    }
    //-->
    </script>

    ERROR
    Microsoft JScript runtime error: Object expected
    <input type="button" name="submit" value="Click" onclick="javasc ript:test(field 1.value,field2. value)"/>
    This part of the line is highlighted when in debug:
    javascript:test (field1.value,f i



    I know I have probably done something really simple, please help!
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    try changing
    [code=javascript]
    <input type="button" name="submit" value="Click" onclick="javasc ript:test(field 1.value,field2. value)"/>
    [/code]
    to
    [code=javascript]
    <input type="button" name="submit" value="Click" onclick="test(f ield1.value,fie ld2.value)"/>
    [/code]
    please remember to use CODE tags when posting - it makes provided code easier to read.

    And also, this is the PHP forum, not javascript.

    Comment

    • kerriejones
      New Member
      • Mar 2007
      • 8

      #3
      Login - javascript execution

      I am trying to create a simple login routine, and am failing completely, I have tried to simplify the test and still no luck. This code is in a php page!

      HTML
      [HTML]<form method="post" action="" >
      <div>
      <input type="text" name="field1"/>
      <input type="password" name="field2"/>
      <input type="button" name="submit" value="Click" onclick="javasc ript:test(field 1.value,field2. value)"/>
      </div>
      </form>
      [/HTML]
      SCRIPT
      [CODE=javascript]<script type="javascrip t">
      <!--
      function test(field1,fie ld2)
      {
      echo "in the test<br>";
      alert ("i am in the code");
      return;
      }
      //-->
      </script>
      [/CODE]
      ERROR
      Microsoft JScript runtime error: Object expected
      <input type="button" name="submit" value="Click" onclick="javasc ript:test(field 1.value,field2. value)"/>
      This part of the line is highlighted when in debug:
      javascript:test (field1.value,f i

      I have tried all of the following onclick commands and still the same error
      onclick="javasc ript:test(field 1.value,field2. value)"
      onclick="javasc ript:test(field 1,field2)"
      onclick="test(f ield1.value,fie ld2.value)"
      onclick="test(f ield1,field2)"

      I know I have probably done something really simple, please help!
      Last edited by acoder; Dec 14 '07, 08:52 AM. Reason: Added code tags

      Comment

      • kerriejones
        New Member
        • Mar 2007
        • 8

        #4
        Mark,

        This does not work either. I have republished the problem in the correct area!

        Comment

        • clai83
          New Member
          • Dec 2007
          • 41

          #5
          I've been creating a login script as well. And actually I finished it in firefox, and it worked fine with safari, and opera, but not IE.

          It would be great if someone were to post the solution to this.

          This particular error also comes up in Zend Studio when doing a debug session.

          IE strikes again -_-

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by kerriejones
            I am trying to create a simple login routine, and am failing completely, I have tried to simplify the test and still no luck. This code is in a php page!
            You have an echo statement inside a JavaScript statement. Firstly, that should appear in PHP tags. Secondly, it needs to be valid JavaScript, e.g. an alert statement.

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Originally posted by clai83
              I've been creating a login script as well. And actually I finished it in firefox, and it worked fine with safari, and opera, but not IE.
              What error did you get in IE? Post your code.

              Comment

              • clai83
                New Member
                • Dec 2007
                • 41

                #8
                Originally posted by acoder
                What error did you get in IE? Post your code.
                I have similar code to kerriejones (the javascript part not the PHP).

                [HTML]
                <input
                class="shortInp utField"
                id="username"
                name="username"
                type="text"
                title="<?php echo $html['usertitle']; ?>"
                maxlength="40"
                value="<?php if (isset($clean['username'])) { echo $clean['username'];} else {echo "";}?>"
                tabindex="1"
                onfocus="this.h asFocus=true; <?php echo $html['fieldcheck']; ?>;"
                onkeyup="<?php echo $html['fieldcheck']; ?>"
                onblur="this.ha sFocus=false; <?php echo $html['fieldcheck']; ?>;"
                />
                [/HTML]

                The problem I'm having is the $html['fieldcheck'] variable. This variable will either be

                [PHP]
                $html['fieldcheck'] = "fieldCheck('ja panese');";
                $html['fieldcheck'] = "fieldCheck('en glish')";
                [/PHP]

                I get the exact same error kerriejones does, where

                Microsoft JScript runtime error: Object expected

                The function fieldCheck is fairly lengthy but here is the basic structure

                [CODE=javascript]
                function fieldCheck(lang uage) {
                //set some vars and regex stuff
                var username = document.login. username;
                //for example

                if (username.value .length === 0) {
                if (language == 'english') {
                //print a english error in paragraph innerHTML
                }
                else {
                //print a japanese error in paragraph innerHTML
                }
                }

                }
                [/CODE]

                I'm a complete newb to javascript. It may be simple, I just can't seem to find it. I'm not sure why there is a JScript runtime error, am I not telling the browser correctly that I'm using javascript. I used <script type="text/javascript" src="something. js" ></script> in the head element. Should I be using something else? Or is there something about IE javascript handling I don't know about. (probably is)

                Hopefully I've given enough information

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  Originally posted by clai83
                  I have similar code to kerriejones (the javascript part not the PHP).

                  [HTML]
                  <input
                  class="shortInp utField"
                  id="username"
                  name="username"
                  type="text"
                  title="<?php echo $html['usertitle']; ?>"
                  maxlength="40"
                  value="<?php if (isset($clean['username'])) { echo $clean['username'];} else {echo "";}?>"
                  tabindex="1"
                  onfocus="this.h asFocus=true; <?php echo $html['fieldcheck']; ?>;"
                  onkeyup="<?php echo $html['fieldcheck']; ?>"
                  onblur="this.ha sFocus=false; <?php echo $html['fieldcheck']; ?>;"
                  />
                  [/HTML]

                  The problem I'm having is the $html['fieldcheck'] variable. This variable will either be

                  [PHP]
                  $html['fieldcheck'] = "fieldCheck('ja panese');";
                  $html['fieldcheck'] = "fieldCheck('en glish')";
                  [/PHP]
                  Maybe it's the double semi-colon. Which line does the error occur on?

                  Comment

                  Working...