Re: [SLUG] Javascript Problem

From: Paul M Foster (paulf@quillandmouse.com)
Date: Sun Oct 15 2006 - 22:10:07 EDT


Daniel Jarboe wrote:
> Paul,
>
> Where are you having the problem? Converting the text to an integer,
> constructing the string, using the onchange event, updating the value in
> the form field below to contain the string of spaces, or what? Hard to
> know what you are missing when you don't say what you have. Writing a
> complete answer for you without more information would probably be doing
> you a disservice (this sounds like it might be homework related?).
>

???

1) AFAIK, Javascript will blithely convert text entered into a text
field into a numeric without any prompting, given the proper context.
Example: the user enters '7' in a text field and Javascript will
interpret it as 7.

2) Using the onChange event? Maybe. Though it's pretty straightforward--
<input name="myfield" type="text" size="5" onChange="some_javascript">
The javascript is contained earlier in the file, between a matched pair
of <script>/</script> tags.

Here's the original post:

I'd like to have a form where the user enters a number, generates an
onChange() event, and the form beneath creates a set of text input
blanks corresponding to the number the user entered. All dynamically,
not generated by pushing a button first. I've been checking my texts and
googling, and I must be missing something.

Further explained:

Originally, the form has some fields on it, one of which is a field
asking for a number. When the user enters a number in that field and
then moves off of it (generating an onChange event), a space opens up
somewhere else on the form with a number of text fields. If the user
enters the number '3' in the blank, the onChange()/Javascript/etc.
creates 3 text fields named, for example, 'field_1', 'field_2' and
'field_3'.

Some hints:

If you onChange() javascript generates calls to document.write(), it
will force a new form to appear, not the modified original form. This is
due to the way intrinsic event handlers work. So that way won't work.

Apparently part of the solution to this may lie in having a span or
other tag with an id that is known to the javascript, which it then can
modify by creating the new fields within it.

Honestly, I didn't think the original post was that vague, nor did I
think this was non-trivial (for someone very familiar with DOM,
Javascript, and maybe AJAX). I just don't happen to be fully familiar
with all that stuff

Paul

-- 
Paul M. Foster
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS).  Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 17:59:36 EDT