By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,400 Members | 1,334 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,400 IT Pros & Developers. It's quick & easy.

need to display error msg in a divtag under tr tag

P: 14
i have a following form.
Expand|Select|Wrap|Line Numbers
  1.     <form id="frm_signup">
  2.     <b>please fill the following registration form.All the fields are compulsory</b><br/><br/>
  4.         <table border="0" cellpadding="" cellspacing="" id="register-table"> 
  6.         <tr> 
  7.         <td >Username</td><td>:<span style="color:#FF0066">*</span></td> 
  8.         <td id="username_row" ><input type=text id="username" name="username" value="" /> 
  9.         <div class="er_msg"></div></td> 
  10.         </tr> 
  12.         <tr> 
  13.         <td >Password</td><td>:<span style="color:#FF0066">*</span></td> 
  14.         <td id="pword_row" ><input type="password" id="pword" name="pword" value="" /> 
  15.         <div class="er_msg"></div></td></tr> 
  16. </table>
  17. <input type="button" id="onRegister" onclick="onRegister()"/>
  18. </form>
during validation if username field is empty i want to display error msg in the
div tag corresponding to username row.

so how can i display the msg in username's div tag.

if i use document.getElementById, then the same msg will display for username and password and whereever the div tag appears.

i don't want to use seperate id for each div for each input field.

i got this piece of code from sites registration form(under advertisers tab, while asking personal details).

i think the following piece of code can apply to my problem
Expand|Select|Wrap|Line Numbers
  1. function onRegister()
  2. {
  3. MYTABLE=document.getElementById('register-table');
  4. for (i=0;i<MYTABLE.rows.length;i++) {
  6. //MYTABLE.rows[i].div.innerHTML="enter value";
  7. alert(MYTABLE.rows[i]);
  8. }
can any one think on those lines

can anyone help me pls....
Nov 18 '08 #1
Share this Question
Share on Google+
2 Replies

P: 607
u can use this for time being

<style type="text/css">
color: #FF0000;
font-family: times;
<script type="text/javascript">
function doRegister()
//alert("Coming Inside");
document.getElementById('username_row').innerHTML+ ='<div class="er_msg">Please Enter User Name</div>';
return false;
document.getElementById('pword_row').innerHTML+='< div class="er_msg">Please Enter Password</div>';
return false;
return true;
<form id="frm_signup">
<b>please fill the following registration form.All the fields are compulsory</b><br/><br/>

<table border="0" cellpadding="" cellspacing="" id="register-table">

<td >Username</td><td>:<span style="color:#FF0066">*</span></td>
<td id="username_row" ><input type="text" id="username" name="username" value="" /></td>

<td >Password</td><td>:<span style="color:#FF0066">*</span></td>
<td id="pword_row" ><input type="password" id="pword" name="pword" value="" />
<div class="er_msg"></div> </td>
<input type="button" value="validate Form" onclick="return doRegister();">
Nov 18 '08 #2

Expert Mod 15k+
P: 16,027
I think that's the very thing which kummu4help wanted to avoid.

Use parentNode to get to the <td> element from the input element and then from there, you can use td.getElementsByTagName("div")[0] to get the div element for displaying the error message.
Nov 18 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.