I'm trying to make it so that if the user sets focus to a form element
(text), it automatically sets focus to the very next form element. This
will, in effect, prevent the user from modifying the value. I know I can do
this by setting the form element to 'readonly' but that's not possible as
I'll need to modify that value elsewhere in my JS. Anyway...
I know I can do something like this:
document.forms[1].elements[4].focus().
Only problem for me with the above method is that I'm generating my form
dynamically so I won't know a) which element number the current field is and
b) which, if any, is the next element. I've tried setting up an event
handler so:
OnFocus='this.n extSibling.focu s();'
but that doesn't work. Apparently, I can't use nextSibling when working
with a form element. So I'm wondering how I can do what I'm needing to do?
Any help would be greatly appreciated!
thnx,
Chris 15 2846
Christoph wrote on 30 jan 2006 in comp.lang.javas cript: I know I can do this by setting the form element to 'readonly' but that's not possible as I'll need to modify that value elsewhere in my JS.
1 you can write the value of a readonly <input> element with javascript
2 you cannot change the readonlyness of an <input> element with javascript
3 however, you can use "disabled" to your advantage.
<input id=x disabled>
<script type="text/javascript">
var x = document.getEle mentById('x')
x.value = 'hi world'
alert(x.disable d)
x.disabled = false
</script>
Do not mess with focus() to restrain the user!
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Christoph wrote: [...] Only problem for me with the above method is that I'm generating my form dynamically so I won't know a) which element number the current field is and b) which, if any, is the next element. I've tried setting up an event handler so:
OnFocus='this.n extSibling.focu s();'
but that doesn't work.
It does not work because `this.nextSibli ng' does not refer to an Element
object that represents a form control but probably a TextNode object that
has no such method.
Apparently, I can't use nextSibling when working with a form element.
You can.
So I'm wondering how I can do what I'm needing to do?
Iterate until you encounter a node that represents a form control.
Quickhack:
function isMethodType(s)
{
return (s == "function" || s == "object");
}
function getNextControl( o)
{
if (o)
{
while ((o = o.nextSibling))
{
if (isMethodType(t ypeof o.focus)
&& /input|button|se lect/.test(o.tagName .toLowerCase()) )
{
return o;
}
}
}
return {focus: function() {}};
}
<... onfocus="getNex tControl(this). focus();"
PointedEars
> "Evertjan." <ex************ **@interxnl.net > wrote: news:Xn******** ************@19 4.109.133.242.. .. Christoph wrote on 30 jan 2006 in comp.lang.javas cript: I know I can do this by setting the form element to 'readonly' but that's not possible as I'll need to modify that value elsewhere in my JS. 1 you can write the value of a readonly <input> element with javascript 2 you cannot change the readonlyness of an <input> element with javascript
I thought one could toggle readOnly between true and false.
What would the situation be that this does not work in?
3 however, you can use "disabled" to your advantage. <input id=x disabled>
<button type="button" onclick="x.read Only=(x.readOnl y)?false:true;
x.focus(); x.select();">to ggle readOnly</button>
<script type="text/javascript"> var x = document.getEle mentById('x') x.value = 'hi world' alert(x.disable d) x.disabled = false </script> Do not mess with focus() to restrain the user!
--
BootNic Tuesday, January 31, 2006 12:53 PM
Inform all the troops that communications have completely broken down.
*Ashleigh Brilliant*
BootNic wrote on 31 jan 2006 in comp.lang.javas cript: <button type="button" onclick="x.read Only=(x.readOnl y)?false:true; x.focus(); x.select();">to ggle readOnly</button>
A <button> is always a button.
onclick="x.read Only=!x.readOnl y;"
try:
==============
<input id='x' readonly>
<script type="text/javascript">
var x = document.getEle mentById('x')
</script>
<button type="button"
onclick="x.read Only=!x.readOnl y;">
toggle readOnly</button>
===============
Indeed it works!
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
BootNic wrote: "Evertjan." [...] wrote: [...] Christoph wrote on 30 jan 2006 in comp.lang.javas cript: I know I can do this by setting the form element to 'readonly' but that's not possible as I'll need to modify that value elsewhere in my JS. 1 you can write the value of a readonly <input> element with javascript
2 you cannot change the readonlyness of an <input> element with javascript
I thought one could toggle readOnly between true and false.
You can, but as was said correctly, you do not have to in order to change
the value of the respective control.
What would the situation be that this does not work in?
An unsupportive DOM, particulary a DOM that does not implement the
HTMLInputElemen t interface of the W3C DOM. However, such DOMs are rare
nowadays: this property is supported r/w for those element objects by the
the Gecko DOM, the IE4+ DOM, the Opera 6+ DOM and the KHTML 2.2+ DOM. That
covers practically almost all known HTML user agents, including Mozilla,
Mozilla Firefox, Internet Explorer 4+, Opera 6+, Konqueror 2.2+ and Safari.
It does not cover Netscape 4.x, for example. 3 however, you can use "disabled" to your advantage.
<input id=x disabled>
<button type="button" onclick="x.read Only=(x.readOnl y)?false:true; x.focus(); x.select();">to ggle readOnly</button>
0. The button will be useless to users without client-side script support.
1. Referring to an element object by the ID of the element it represents is
a deprecated and often IE-only practice. If the `button' element is
descendant of the same `form' element as the `input' element, it is
better to use this.form.eleme nts['x'] instead.
2. readOnly is a boolean property already.
3. The `button' element is not backwards compatible and it is unnecessary
here (as the element content is a text node).
<script type="text/javascript">
document.write(
'<input type="button" value="toggle readOnly"'
+ 'onclick="var x = this.form.eleme nts['x'];'
+ ' x.readOnly = !x.readOnly; x.focus(); x.select();">') ;
</script> <script type="text/javascript"> var x = document.getEle mentById('x') x.value = 'hi world' alert(x.disable d) x.disabled = false </script>
Do not mess with focus() to restrain the user!
You are not referring to this, so do not quote it.
PointedEars
JRS: In article <Xu************ *****@newssvr24 .news.prodigy.n et>, dated
Tue, 31 Jan 2006 17:53:59 remote, seen in news:comp.lang. javascript,
BootNic <Bo*****@bounce .prodigy.net> posted : <button type="button" onclick="x.read Only=(x.readOnl y)?false:true;
^^^^^^^^^^^^ Ugh!x.focus(); x.select();">to ggle readOnly</button>
As is well-known, I dislike using new-fangled constructs instead of
older equivalents as soon as they become available in the latest
systems, since that handicaps those with older software.
And I don't recall ever seeing <button ... > in anyone else's source.
But (with or without type=button) it works in my IE4, and is acceptable
to two local testers.
In which versions, at about what date, did it appear in browsers?
Are there other special cases of <input type=... > that are widely
implemented?
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Dr John Stockton said the following on 2/1/2006 11:16 AM: JRS: In article <Xu************ *****@newssvr24 .news.prodigy.n et>, dated Tue, 31 Jan 2006 17:53:59 remote, seen in news:comp.lang. javascript, BootNic <Bo*****@bounce .prodigy.net> posted : <button type="button" onclick="x.read Only=(x.readOnl y)?false:true; ^^^^^^^^^^^^ Ugh! x.focus(); x.select();">to ggle readOnly</button>
As is well-known, I dislike using new-fangled constructs instead of older equivalents as soon as they become available in the latest systems, since that handicaps those with older software.
<button> is not a "new-fangled" construct though. It is at least 7 years
old and probably older.
And I don't recall ever seeing <button ... > in anyone else's source.
It is seen quite a lot.
But (with or without type=button) it works in my IE4, and is acceptable to two local testers.
In which versions, at about what date, did it appear in browsers?
It is supported by IE4+, NS6+ and any later (modern) browser. NN4 didn't
support button though.
Are there other special cases of <input type=... > that are widely implemented?
Such as what?
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
> "Evertjan." <ex************ **@interxnl.net > wrote: news:Xn******** ************@19 4.109.133.242.. .. BootNic wrote on 31 jan 2006 in comp.lang.javas cript: <button type="button" onclick="x.read Only=(x.readOnl y)?false:true; x.focus(); x.select();">to ggle readOnly</button> A <button> is always a button.
If I were to put a button in a form without type="button", and it was
not the submit button, some browsers treat it as a submit button. I
usually add it for that reason.
IE 6 does not seem to have any issues with it.
FireFox 0.8.0
NetScape 7.2
Mozilla 1.7.12
Opera 8.51
All treat it as a submit button.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
</head>
<body>
<form id="a" name="a" action="http://www.google.com/search">
<input name="q" type="text" value="button collector"><br>
<button type="button" onclick="alert( 'hello')">Alert
Hello</button><br>
<button onclick="alert( 'Good Bye')">Alert Good Bye</button><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
--
BootNic Wednesday, February 01, 2006 10:12 PM
When I was young, I was put in a school for retarded kids for two
years before they realized I actually had a hearing loss...and they
called ME slow!
*Kathy Buckley*
BootNic wrote: "Evertjan." [...] wrote: BootNic wrote on 31 jan 2006 in comp.lang.javas cript: <button type="button" onclick="x.read Only=(x.readOnl y)?false:true; x.focus(); x.select();">to ggle readOnly</button> A <button> is always a button.
If I were to put a button in a form without type="button", and it was not the submit button, some browsers
All widely distributed browsers except IEeek do.
treat it as a submit button.
Because it is specified so:
<URL:http://www.w3.org/TR/html4/interact/forms.html#edef-BUTTON>
(The third value of an attribute declaration is the default value.)
[...] IE 6 does not seem to have any issues with it.
Because IEeek is broken. Nothing new here.
PointedEars This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: CJ |
last post by:
Why won't this work?
I am passing the name of the form (I have two that use this validation
script) but I keep getting an error.
Error reads: "document.which_form.name is null or not an object"
HTML-----------
Form is ----> <form action="thanks.php" method="post" name="contact_form"
id="contact_form">
Name -------> <input type="text" name="name" id="name" size="25">
Button sends code -----> <input type="button" value="Submit Form"
|
by: mcanedo |
last post by:
Hi:
I have several text elements in a form.
Some of they are filled by the user, and then some are automatically filled
based on the user input.
Therefore I do not want the user to be able to write on the autofilled text
elements.
I have come to the idea of give those elements the event
onFocus=functiontoMovetoNextElement()
Then my question is how can I do that using the elements array?
|
by: john woo |
last post by:
Hi
I'm not good at JS, but want to get more about it.
I want to use a JSP (the java code just used to get date, the rest are
html and javascript),
to display a table. the requirement is the all rows in even number in
light-blue, rows in odd number in light gray, when a mouse clicks on a
row, this row gets highlighted and in yellow, and it keeps highlighted
|
by: Deniz Bahar |
last post by:
Hi,
I'm working with a single linked list and want to delete elements by
searching through the list (starting form the HEAD) then finding the
element, then doing the following:
NewElement = CurrentElement->next;
CurrentElement->next = NewElement->next->next;
free(NewElement);
|
by: Joseph Garvin |
last post by:
When I first came to Python I did a lot of C style loops like this:
for i in range(len(myarray)):
print myarray
Obviously the more pythonic way is:
for i in my array:
print i
| |
by: zek2005 |
last post by:
Hi!!!
I've made a form with a 'select' statement through a
echo('<select name="res">');
echo('<option selected value=""> Select option</option>");');
while($row = mysql_fetch_array($resumen))
{
echo('<option value="' .$row. '">'
..strtoupper($row). '</option>');
|
by: yawnmoth |
last post by:
Say I have two input elements and that I wanted to make it so that when
the first ones input was what it should be, the focus would
automatically be shifted to the next input element.
ie. something like...
<input onkeyup="if (this.value.length == this.maxlength)
document.forms.elements.focus()" value="whatever"
maxvalue="x" type="text" />
<input value="whatever" maxvalue="x" type="text" />
|
by: dlite922 |
last post by:
Before traversing my code, here's what my goal is and what this function does:
I have a table of fields that dynamically grows as the user enters information. A minimum of 3 rows must always exist. (read the psedo code and comment if you need to know what it does)
disregard the debugging , commented alerts.
What i'm trying to do is without passing the ID or field that called this function, set the focus to the next element. what's...
|
by: removeps-groups |
last post by:
How to display table and select next to each other?
<html>
<body>
<table border=1 style="display:inline-table">
<tr><td>Hello1</td></tr>
<tr><td>Hello2</td></tr>
<tr><td>Hello3</td></tr>
<tr><td>Hello4</td></tr>
<tr><td>Hello5</td></tr>
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |