www.webdeveloper.com
+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2011
    Posts
    67

    How does it not work after adding <table> tage

    Hi there,
    Can some one tell me why the two same codes below one without table tag works and another with table tag not? Thanks,

    Below code works:
    Code:
    <form name="register" id="registerForm" action="inc/peregister.php" method="post">
                    <label class="labelLong" for="penewuser">Please choose a user name: </label><input type="text" name="penewuser" id="penewuser" size="24" /><span class="error">The name is taken, please choose another</span><br />
                    <label class="labelLong" for="penewpass">Please choose a password: </label><input type="password" name="penewpass" id="penewpass" size="24" /><span class="error">password must not be blank</span><br />
    Below code does not work:
    Code:
    			<table bordre=0><tr>
                    <td><label class="labelLong" for="penewuser">Please choose a user name: </label></td><td><input type="text" name="penewuser" id="penewuser" size="24" /></td><td><span class="error">The name is taken, please choose another</span></td></tr>
                    <tr><td><label class="labelLong" for="penewpass">Please choose a password: </label></td><td><input type="password" name="penewpass" id="penewpass" size="24" /></td><td><span class="error">password must not be blank</span></td></tr>
    ....
    Javascript:
    Code:
    $(document).ready(function() {
    	/* new user name check */
    	$('#penewuser').blur(function() {
    	    var newName = $(this).val();
    	    $.post('inc/peRegister.php', {
    	        formName: 'register',
    	        penewuser: newName
    	    }, function(data){
    	    	var usernameCount = data;
    	    	if(1 == usernameCount){
    	    		$('#penewuser').next('.error').innerHTML = "What?";
    				$('#penewuser').next('.error').css('display', 'inline');
    	    	} else {
    	    		$('#penewuser').next('.error').css('display', 'inline');
    				$('#penewuser').next('.error').innerHTML = usernameCount;
    	    	}
    		}, 'html');
    	});
    });

  2. #2
    Join Date
    May 2006
    Location
    Russia, Rostov-on-Don
    Posts
    1,153
    in the first code $('#penewuser').next('.error') finds <span class="error">

    but in the second code <input type="text" name="penewuser" id="penewuser" size="24" /> is the only child of its parent element

    p.s. <table bordre=0> must be <table border="0">
    use [code]YOUR CODE GOES HERE[/code] or burn in Hell

  3. #3
    Join Date
    Feb 2011
    Posts
    67
    Quote Originally Posted by Padonak View Post
    in the first code $('#penewuser').next('.error') finds <span class="error">

    but in the second code <input type="text" name="penewuser" id="penewuser" size="24" /> is the only child of its parent element

    p.s. <table bordre=0> must be <table border="0">
    Thanks, Pandonak. I don't understand

    in the second code <input type="text" name="penewuser" id="penewuser" size="24" /> is the only child of its parent element. After </td><td>, it's followed by <span class="error"> also.

    How come $('#penewuser').next('.error') can not find <span class="error">
    after </td><td>?

  4. #4
    Join Date
    May 2006
    Location
    Russia, Rostov-on-Don
    Posts
    1,153
    .next([selector])
    Description: Get the immediately following sibling of each element in the set of matched elements, optionally filtered by a selector.
    it is searching for siblings inside the parent element (which is TD) and <span class="error"> as you can see is nested after </td><td> (i.e. inside another TD). that's why it finds nothing
    use [code]YOUR CODE GOES HERE[/code] or burn in Hell

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

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
HTML5 Development Center



Recent Articles