/    Sign up×
Community /Pin to ProfileBookmark

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 />
[/CODE]

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>
….[/CODE]

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’);
});
});[/CODE]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@PadonakMay 10.2012 — in the first code [i]$('#penewuser').next('.error')[/i] finds <span class="error">

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

p.s. <table [COLOR="Red"]bordre[/COLOR]=0> must be <table [COLOR="Green"]border="0"[/COLOR]>
Copy linkTweet thisAlerts:
@wowauthorMay 11.2012 — in the first code [i]$('#penewuser').next('.error')[/i] finds <span class="error">

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

p.s. <table [COLOR="Red"]bordre[/COLOR]=0> must be <table [COLOR="Green"]border="0"[/COLOR]>[/QUOTE]


Thanks, Pandonak. I don't understand

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

How come [i]$('#penewuser').next('.error')[/i] can not find <span class="error">

after </td><td>?
Copy linkTweet thisAlerts:
@PadonakMay 11.2012 — [B].next([selector])[/B]

Description: Get the immediately following [COLOR="Red"]sibling[/COLOR] of each element in the set of matched elements, optionally filtered by a selector.[/QUOTE]


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
×

Success!

Help @wow spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...