querying textfields outside of forms...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Markus

    querying textfields outside of forms...

    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="JavaS cript">
    function update() {
    var ctrls_doc = document;

    ctrls_doc.write ln("<html>");
    ctrls_doc.write ln("<body>");

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

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

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

    ctrls_doc.write ln("</body>");
    ctrls_doc.write ln("</html>");

    ctrls_doc.close ();
    }

    function check()
    {

    alert("FIRST: " + window.document .controls.eleme nts.OpsName.val ue+
    "\n" +
    "SECOND: " + window.document .OpsName2);

    }

    update()
    </script>

    </html>
  • swp

    #2
    Re: querying textfields outside of forms...

    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(fiel d, 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="retu rn tabOnEnter(this ,
    event);">
    =============== =============== =============== =============== =============== ==

    hope this helps,

    swp

    mburki@pdi.com (Markus) wrote in message news:<3eb2498.0 309180934.68469 ed0@posting.goo gle.com>...[color=blue]
    > 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="JavaS cript">
    > function update() {
    > var ctrls_doc = document;
    >
    > ctrls_doc.write ln("<html>");
    > ctrls_doc.write ln("<body>");
    >
    > ctrls_doc.write ln("<form name='controls' >");
    > ctrls_doc.write ln("<table cellpadding='2' cellspacing='2'
    > border='1' height='100%'>" );
    > ctrls_doc.write ln("<td align='center' valign='center' >");
    > ctrls_doc.write ln("Inside FORM: <input type='text'
    > name='OpsName'> ");
    > ctrls_doc.write ln("</td>");
    > ctrls_doc.write ln("</tr>");
    > ctrls_doc.write ln("</table>");
    > ctrls_doc.write ln("</form><br>");
    >
    > ctrls_doc.write ln("Outside FORM: <input type='text'
    > name='OpsName2' ><br><br>");
    >
    > ctrls_doc.write ln("<input type='button' name='CheckMe'
    > value='Check ME' onclick='check( )'>");
    >
    > ctrls_doc.write ln("</body>");
    > ctrls_doc.write ln("</html>");
    >
    > ctrls_doc.close ();
    > }
    >
    > function check()
    > {
    >
    > alert("FIRST: " + window.document .controls.eleme nts.OpsName.val ue+
    > "\n" +
    > "SECOND: " + window.document .OpsName2);
    >
    > }
    >
    > update()
    > </script>
    >
    > </html>[/color]

    Comment

    Working...