querying textfields outside of forms...

M

Markus

Hi,

I am trying to query the value of a textfield outside of a form but
with no success so far... the reason why I am not using a form is that
there seams to be an annoying issue with hitting the [Enter] key (at
least in Mozilla) when there is only one textfield in the form... the
[Enter] key seams to trigger some type of a submit... but when the
textfield is defined outside of a form this is not an issue... However
I don't know how to access the value for the textfield outside the
form... see example below...

any help is greatly appreciated...

Thanks,
Markus.



<html>
<script language="JavaScript">
function update() {
var ctrls_doc = document;

ctrls_doc.writeln("<html>");
ctrls_doc.writeln("<body>");

ctrls_doc.writeln("<form name='controls' >");
ctrls_doc.writeln("<table cellpadding='2' cellspacing='2'
border='1' height='100%'>");
ctrls_doc.writeln("<td align='center' valign='center'>");
ctrls_doc.writeln("Inside FORM: <input type='text'
name='OpsName'>");
ctrls_doc.writeln("</td>");
ctrls_doc.writeln("</tr>");
ctrls_doc.writeln("</table>");
ctrls_doc.writeln("</form><br>");

ctrls_doc.writeln("Outside FORM: <input type='text'
name='OpsName2'><br><br>");

ctrls_doc.writeln("<input type='button' name='CheckMe'
value='Check ME' onclick='check()'>");

ctrls_doc.writeln("</body>");
ctrls_doc.writeln("</html>");

ctrls_doc.close();
}

function check()
{

alert("FIRST: " + window.document.controls.elements.OpsName.value+
"\n" +
"SECOND: " + window.document.OpsName2);

}

update()
</script>

</html>
 
S

swp

try using something like this to get around the "[Enter]" problem,
which seems to be the heart of your issue.

as always, be careful of line wrapping...
=============================================================================
function tabOnEnter(field, evt) {
var keyCode = document.layers ? evt.which : document.all ?
evt.keyCode : evt.keyCode;
if (keyCode != 13)
return true;
else {
getNextElement(field).focus();
return false;
}
}

use it like this:
<input name=svar size=35 value='' OnKeyDown="return tabOnEnter(this,
event);">
=============================================================================

hope this helps,

swp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top