We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,231 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

basic jquery function

html file

 <div id = "right_login">
            <form  id='login' action='login.php' method='POST' name=''>
             <h1>Log in to your account!</h1>
               <?php
                //print errors
                if(array_key_exists('log_error', $_SESSION) && !empty($_SESSION['log_error']))
                {
                    $log_error_r = $_SESSION['log_error'];
                    echo "<span style='background-color:#D00000;'> $log_error_r <br/></span>";
                    unset($_SESSION['log_error']);
                }
              ?>
                <div>
                    <label>Username:</label> 
                    <input type="text" name="username" id="login_username" class="login_field" value="" />
                </div>           

                <div>
                    <label>Password</label>
                    <input type="password" name="password" id="login_password" class="login_field" value=" "/>
                 </div>          

                <p class="forgot"><a href="#">Forgot your password?</a></p>
                <div id="submit">
                     <button type="submit">Log in</button>    
                </div>
             </form>
            </div>

jquery file

    var search = "Search...a";
    var username = 'Username';
    var email = 'Email';
    alert(test01);
    $('#login_username').attr('value', search).focusin(function()
    {   alert("test02");
        //$(this).css('background-color', 'yellow');
        if($(this).val() == search)
        {
            $(this).attr('value', '');
        }
    }).focusout(function()
    {
        //$(this).css('background-color', 'white');
        if($(this).val() == '')
        {
            $(this).attr('value', na);
        }
    });

for some reason in jquery file its print "test01" but it doesnt go inside "test02". i dont understand why it wont go insdie a function? am i missing some thing?

4
Contributors
3
Replies
2 Days
Discussion Span
6 Months Ago
Last Updated
4
Views
hwoarang69
Posting Pro
569 posts since Feb 2012
Reputation Points: 6
Solved Threads: 0
Skill Endorsements: 7

Can you clarify what you mean by

for some reason in jquery file its print "test01" but it doesnt go inside "test02".

I'm not following the logic. Also on line 4 the alert method is passing a variable called test01. Where you trying to pass a string instead?

JorgeM
Industrious Poster
4,019 posts since Dec 2011
Reputation Points: 297
Solved Threads: 548
Skill Endorsements: 115

Is this page being loaded via AJAX? If so, use delegate instead of focusin and focusout.

stbuchok
Practically a Posting Shark
876 posts since May 2011
Reputation Points: 138
Solved Threads: 124
Skill Endorsements: 2

my guess is that you load your javascript file at the top of the page before the dom loads, so when line 5 executes, #login_username does not exist yet and so your focusin and focusout handlers are not attached.

You can either move your script tag to the bottom of your html document, or wrap your init code in document.ready:

$(document).ready(function () { [init code here] })

scrager
Newbie Poster
15 posts since Feb 2009
Reputation Points: 32
Solved Threads: 2
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0993 seconds using 2.79MB