Get form information through DOM node manipulation

Source: Internet
Author: User

This is the story of the previous whim to manipulate the form with the DOM node's relationship ...

Things are like this, is probably a platform after the registration of the message function, the administrator can log in after the message to reply. This page, that is, through foreach to obtain the information in the database, the user's ID and message information at the end of the appearance of the interface as if (my drawing talent is really a lever drop) (shy cover face)

Yes, it's so cool.

On the left is the user's ID in the middle is the user message content after each has a Reply button admin Click Reply after the corresponding message box below will appear a text box, then can happily reply. Yes, there's a reply. Send and delete functions. Maybe it's like a piece, and you'll appreciate it.

Then start the code as follows

1<div style= "border:1px solid" >2<ul>3<c:foreach items= "$ (meslist)"var= "Meslist" >4<li>56$ (meslist.name) <li>$ (meslist.email) </li><span clss= "Timer" >$ (Meslist.item) </span>78<p> Admin Hello:<br/> $ (meslist.contene) </p>9<div><button onclick= "Reply (this)" > Reply </button></div> <!--Click here to appear text box--Ten<form id= "Replycon" name= "Replycon" style= "Display:none" > One<textarea cols= "></textarea>" A<input type= "Submit" class= "sendbtn" value= "send" onclick= "sendmsgs (This)" > -<input type= "reset" class= "cancelbtn" value= "Cancel" onclick= "cancelmsg (This)" > -</form> the</li> -</c:forEach> -</ul> -</div>

Probably just after clicking on the reply, a text box will appear, editing the good content, you can submit it. So I gave the reply () function passed the parameter this, the thought of defining a function to pass in a formal parameter, in the function inside the operation is not OK, but life is not ten. Added after each time regardless of the number of users to click on the Reply button, will be in the area of the first user to appear in the text box, after half a day and there is no egg use, so I think of a very magical method, rather let the formal parameter along the scope of the chain to find the parent node and then go down, to find the current <div > Make it appear as block, that's it. Sure enough, I solved the wit, the code is as follows

        function Replay (o) {    var  o.parentnode.parentnode.getelementsbytagname (' form ') [0]. style.display= "Block";        }

Sure enough, the text box will appear in its corresponding area after each click.

However, after clicking the Send button to get the user name information in the

function sendmsgs (o) {  var rname=o.parentnode.parentnode.getelementsbytagname (' h3 ') [0]. getElementsByTagName (' li ') [0].innerhtml;         var content=o.parentnode.getelementsbytagname (' textarea ') [0].value;        }

Then happily solved the problem.

Finish...

Get form information through DOM node manipulation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.