473,394 Members | 1,740 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,394 software developers and data experts.

how to write words into a div from a text input?

I was trying to make some experiences with javascript ,
making a div response to a text input but cannot say what am doing bad so if
anyone could help with the script,
many Thanks
the script follows
<script type="text/javascript">
function I(form)
{
if(form.e2.value=="")
document.getElementById("dc").innerHTML="something ";
}
</script>
<p >
<form name="form">
<input name="e2" size="20" type="text">
<select name="e1">
<option>option.....
<option>option1
</select>
&nbsp;
<input src="" onclick="I(form)" align="right" type="image" width="60"
height="49"></p>
</form>
<p>&nbsp;</p>
<div id="dc">
</div>
Feb 1 '07 #1
2 1624
Offm wrote:
I was trying to make some experiences with javascript ,
making a div response to a text input but cannot say what am doing bad so
if anyone could help with the script,
many Thanks
the script follows
<script type="text/javascript">
function I(form)
{
if(form.e2.value=="")
document.getElementById("dc").innerHTML="something ";
}
</script>
<p >
<form name="form">
<input name="e2" size="20" type="text">
<select name="e1">
<option>option.....
<option>option1
</select>
&nbsp;
<input src="" onclick="I(form)" align="right" type="image" width="60"
height="49"></p>
Hi, You are sending form to the function.

To debug your code, simple alert your parameters and see what JavaScript say
they are.
In your case:
<script type="text/javascript">
alert ("Received form. form="+form);
function I(form)
{
if(form.e2.value=="")
document.getElementById("dc").innerHTML="something ";
}
</script>

It will probably yell something like 'undefined'.

To fix your script:
1) Make a valid reference to the form in your function
like:
var myForm = document.forms["form"];

or

2) Pass a valid reference to the function from the onClick-handler.
You can use the keyword 'this', but it will reference to the image, not the
form.
onClick='I(this);';

I would advise 1), and when you get a hang of it, you can start using
'this'. (I never use this for such purposes, and always build the reference
inside the function, but that is personal taste and total imcompetence on
my side.)

Regards,
Erwin Moller
</form>
<p>&nbsp;</p>
<div id="dc">
</div>
Feb 1 '07 #2
Erwin Moller wrote:

typo correction: The alert should be in the function of course.

<script type="text/javascript">
function I(form) {
alert ("Received form. form="+form);
if(form.e2.value==""){
document.getElementById("dc").innerHTML="something ";
}
}
</script>

Regards,
Erwin Moller
Feb 1 '07 #3

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

Similar topics

1
by: Scott Navarre | last post by:
Hello, I have noticed that when using JavaScript to create a page, the sizes of the text input form elements come out bigger than the size I am trying to set them to. I don't know if it...
2
by: Kai Grossjohann | last post by:
I would like to put a text input field (in the sense of <input type="text">) and an image next to each other, where I know the size in pixels of the image, and I know the total width in em. I...
8
by: BiNZGi | last post by:
Hi I have reduced the problem to this code: <form> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td><input type="text" style="width: 100%;" value="Lorem ipsum dolor...
5
by: Art | last post by:
Hi, I'm using a form text input to display a JavaScript clock. It has no other purpose than that, just show the date and time. What I would like to do now is prevent anything else happening when...
18
by: Diogenes | last post by:
Hi All; I, like others, have been frustrated with designing forms that look and flow the same in both IE and Firefox. They simply did not scale the same. I have discovered, to my chagrin,...
2
by: webandwe | last post by:
Hi, I was just wondering I saw the following question in a test once and now it bug me... The question was: Write a analoghrim in php to write the text "word1 word2 word3 word4" to "word4...
3
omerbutt
by: omerbutt | last post by:
hi there i have a tbl in db which has following fields table name:stock id_no(primary key...autono) part_name(text) price(currency) now i have an asp and htmlbased form in which i have made a...
11
by: Mike Harrison | last post by:
Hi, I have some simple HTML like this: <div id="container" style="width:100%;"> <input type="text" <input type="button" style="float:right;" value="Click here..."> </div> I want the button...
0
by: pazazuzu | last post by:
Hi everyone, I currently have an assignment which I am almost done with but am having problems trying to figure out how to integrate a string function search. I have a text box called...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.