Form Input Question

Form Input Question

Post by cjl » Mon, 31 Oct 2005 01:48:20


Hey all:

I have the following html and javascript:

HTML:
<form name="searchme" action="" onKeyPress="checkSection('searchme');">

JAVASCRIPT:
function checkSection(submitter)
{
changeAnatomy(submitter);
}

function changeAnatomy(submitter)
{
if (document[submitter].query.value.slice(0,2) == '00')
{
document.getElementById('anatomy_table').innerHTML = '<div
class="table_title">Anatomy</div><br> 00 - All<br></div>';
}
}

What I want is that when the user enters two digits and they are '00',
the innerHTML will be changed. What I get is a change only after a
third digit (any digit) is entered. BTW - I know that the checkSection
function looks redundant, but other code to validate the input will go
in there soon.

Where am I going wrong?

-CJL
 
 
 

Form Input Question

Post by Evertjan » Mon, 31 Oct 2005 01:55:05

cjl wrote on 29 okt 2005 in comp.lang.javascript:


The 0 is not there yet at onkeypress? Try onkeyup.

btw: cann't you do this simpler?

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

 
 
 

Form Input Question

Post by cjl » Mon, 31 Oct 2005 02:02:37

Evertjan:



Thank you, onkeyup worked.


Probably.

I have a search form that requires the user to input a six digit code.
There are three tables on the page: Section, Etiology, and Anatomy.
The section and etiology tables are static. However, the anatomy table
must change depending on which section is selected. For example, if
the "Neuro" section digits are keyed then the anatomy table must have
choices for "brain", "head and neck", and "spine". There are 11
different sections, so I need 11 different anatomy tables.

I can't think of another way to do this, but there must be simpler and
more elegant solutions. Any help is appreciated.

-CJL
 
 
 

Form Input Question

Post by Evertjan » Mon, 31 Oct 2005 02:41:13

cjl wrote on 29 okt 2005 in comp.lang.javascript:


What I mean by simpler is:


use "this" wherever possible:

<form action="" onKeyPress="changeAnatomy(this);">

<div id=xxx class="table_title"></div>
<div id=yyy></div>



why the intermediate function?


function changeAnatomy(submitterObj) {
if (submitterObj.query.value.slice(0,2) == '00') {


innerHTML-ing the asymetrical end part of a <div></div> seems illogical,
and I would use <div> and not <br>, but that depends on the css styles,
and only inserting the text looks cleaner and less rpone to mistakes:

document.getElementById('xxx').innerHTML = 'Anatomy'
document.getElementById('yyy').innerHTML = ' 00 - All'
}
}



--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)
 
 
 

Form Input Question

Post by Randy Web » Mon, 31 Oct 2005 02:48:23

cjl said the following on 10/29/2005 1:02 PM:


Select lists or Radio Buttons. They choose the anatomy, they get the table.

--
Randy
comp.lang.javascript FAQ - http://www.yqcomputer.com/
 
 
 

Form Input Question

Post by cjl » Mon, 31 Oct 2005 04:09:42

Evertjan and Randy:

Thank you very much, your points are well taken.

I will rethink my approach, and make it cleaner. I'm going to skip all
the innerHTML mumbo jumbo, and just show / hide some <div>s.

-CJL