473,412 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

I generate a FORM by js,but i can't input anything?

21 function js_reply_msg(node,g_id,u_id,par_id)
22 {
23 node.innerHTML="<FORM><TEXTAREA
name=\"msg_con\"><\/TEXTAREA><br><INPUT type=\"submit\"
value=\"reply\"><\/FORM>"
24 node.nextSibling.nextSibling.innerHTML=""
25 }

My thought is that when i clicked a link,the js function generate the
Form,then get the input and deal with it.
But now ,i generate the FORM,but can't input anything:
when i press the mouse left button,i can input;if i don't ,i can't
input.

Can anyone help me?Thank you

Aug 10 '06 #1
1 1727
firenet wrote:
21 function js_reply_msg(node,g_id,u_id,par_id)
22 {
Don't include line numbers in posted code, indent code properly using 2
or 4 spaces and manually wrap it at about 70 characters to help prevent
auto-wrapping.

23 node.innerHTML="<FORM><TEXTAREA
name=\"msg_con\"><\/TEXTAREA><br><INPUT type=\"submit\"
value=\"reply\"><\/FORM>"
Allowing uncontrolled addition of line breaks will usually add more
errors to your code - manually wrap it.

You can nest double-quotes inside single-quotes and vice versa, ensure
that you insert valid HTML:

node.innerHTML = '<FORM action=""><div>'
+ '<TEXTAREA name="msg_con"></TEXTAREA>'
+ '<br><INPUT type="submit" value="reply">'
+ '</div></FORM>';

That snippet, on its own, seems to 'work' just fine in IE and Firefox.

24 node.nextSibling.nextSibling.innerHTML=""
This line is meaningless in the context of the code snippet you have
posted and causes an error if I just try to run your code in a test
page. Ensure that posted code runs when copy/pasted into a test page
and doesn't display spurious messages.

Blindly navigating down the DOM tree using nextSibling is likely to
cause problems because some browsers will insert extra nodes for
whitespace, others won't. There may be more (or fewer) nodes between
siblings than you expect. You must test the nodes to see if you've
found what you expect, and deal with it if you don't.

25 }

My thought is that when i clicked a link,
What link? You haven't shown any link, or how the function is called.
If you are using an A element and javascript pseudo-protocol, that may
be your issue.
the js function generate the
Form,then get the input and deal with it.
But now ,i generate the FORM,but can't input anything:
Please use proper punctuation, this isn't a chat session.
Capitalisation is important, I shouldn't have to wonder when you've
made a typing error and when you're just being cute..

when i press the mouse left button,i can input;if i don't ,i can't
input.
So the form generates OK, but you have to click in it to give it focus
before entering any text - that is exactly how form controls work. If
you want to create the form and put focus on it, you are better off to
use DOM, then use the textarea's focus method, e.g.

<title>Reply message textarea</title>
<script type="text/javascript">

function addReplyMsg(node)
{
if (!node || !document.createElement) return;

function addEl(parent, tagName, elType){
var t = document.createElement(tagName);
if (typeof elType == 'string' && elType.length){
t.type = elType;
}
parent.appendChild(t);
return t;
}

var oForm = addEl(node, 'form');
oForm.action="";
var oDiv = addEl(oForm, 'div');
var oTA = addEl(oDiv, 'textarea');
oTA.name = 'msg_con';
addEl(oDiv, 'br');
var oSub = addEl(oDiv, 'input', 'submit');
oSub.value = 'Reply';
if (oTA.focus) oTA.focus();
}

</script>

<input type="button" value="Add"
onclick="addReplyMsg(document.getElementById('xx') );">
<div id="xx"></div>
--
Rob

Aug 10 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Richard Gregory | last post by:
Hi, I have the wsdl below, for an Axis web service, and when I select Add Web Refernce in Visual Studio the proxy is missing a class representing the returnedElementsType (see reference.cs below...
0
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional...
2
by: wendallsan | last post by:
Hi all, I know that this should be an easy thing, but I haven't figured out how to get this to work on my server at home. I have a roommate who is using PHPBB on his site on the server and that...
0
by: Slickuser | last post by:
From my PHP page: Grab all data from the database. Go through a loop to generate the HTML. Client side: From the Color drop menu list, if a user change the value. It will grab that value &...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.