473,405 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

passing meta-knowledge about a form element

I need to create a table where each element has certain specific properties.

For example, elements in the first column should always have a range of
0-100, and increment by 1. Elements in column 2 might have a range of
0-360, and increment by 0.1. Altogether there might be 8 elements in
each row.

Since this is basically the same javascript function over and over, I
wonder if there is a way to create some <input> element that might
contain this knowledge in a way that javascript can access it.

For example, could I have

<input type="text" class="percent" onkeypress="javascript:blah(event)">

where the javascript function could retrieve the class value?

Since this is going to be fairly complex, I'd like to make it fairly
self-documenting and simple. It's much easier for a maintainer to
understand class="precent" than "javascript:blah(0,100,1,event)",
especially since I am also going to have to pass navigation information
(is this a border element in the table? what are my neighbors? kind
of information... - so that the actual information might end up being
javascript:blah(0,100,1,5,21,16,18,0,1,0,0,event) to denote the data
type, the 4 neighbors, and the 4 border conditions....
Jan 20 '06 #1
3 1588
VK

Captain Dondo wrote:
I need to create a table where each element has certain specific properties.

For example, elements in the first column should always have a range of
0-100, and increment by 1. Elements in column 2 might have a range of
0-360, and increment by 0.1. Altogether there might be 8 elements in
each row.

Since this is basically the same javascript function over and over, I
wonder if there is a way to create some <input> element that might
contain this knowledge in a way that javascript can access it.

For example, could I have

<input type="text" class="percent" onkeypress="javascript:blah(event)">

where the javascript function could retrieve the class value?


Yes, you can. Though DOM doesn't provide a native method like
getElementsByClassName, but you can write one or use any of already
written of this kind. Also if it's given what you are working only with
inputs within one form, then the task even more simple:

<input type="text" class="percent" onkeypress="blah(event)">
(please note that event handler is not a link, so javascript:
pseudo-protocol is out of business here)
....
var elm = document.form['myForm'].elements;
var len = elm.length;
for (var i=0; i<len; i++) {
switch (elm[i].className) {
case 'percent' :
// your action
break;
case 'degree':
// your action
break;
default:
// no match
}
}
....
you can apply several classes to one element to make the system as
complicated as you want:
<input type="text" class="percent mandatory " onkeypress="blah(event)">
<input type="text" class="integer positive mandatory"
onkeypress="blah(event)">
<input type="text" class="integer positive optional"
onkeypress="blah(event)">
etc.

Jan 20 '06 #2
VK wrote:
Yes, you can. Though DOM doesn't provide a native method like
getElementsByClassName, but you can write one or use any of already
written of this kind. Also if it's given what you are working only with
inputs within one form, then the task even more simple:

<input type="text" class="percent" onkeypress="blah(event)">
(please note that event handler is not a link, so javascript:
pseudo-protocol is out of business here)
OK, noted. I am a javascript newbie....
...
var elm = document.form['myForm'].elements;
var len = elm.length;
for (var i=0; i<len; i++) {
switch (elm[i].className) {
case 'percent' :
// your action
break;
case 'degree':
// your action
break;
default:
// no match
}
}
...
you can apply several classes to one element to make the system as
complicated as you want:
<input type="text" class="percent mandatory " onkeypress="blah(event)">
<input type="text" class="integer positive mandatory"
onkeypress="blah(event)">
<input type="text" class="integer positive optional"
onkeypress="blah(event)">
etc.


Very cool.... So I should be able to retrieve taborder values as well
using this method... And perhaps store general data like # of rows and
columns in a hidden element, so then I can derive most of my nav info....

Thanks,

--Yan
Jan 20 '06 #3
VK

Captain Dondo wrote:
So I should be able to retrieve taborder values as well
using this method...


For elements taborder there is native attribute "tabindex", and all
modern browsers (at least all you need to care about, including IE and
FF) respect this attribute:

<input type="text" name="t1" tabindex="1">
<input type="text" name="t2" tabindex="3">
<input type="text" name="t3" tabindex="2">
<input type="text" name="t4" tabindex="-1">

On tab press focus goes from t1 to t3, and only then to t2. The
negative value I used only on IE and it does what promised: such
element is excluded from taborder so requires an explicit mouse click
for focus.

Of course you need to use it only if you need to i) change the default
taborder or ii) exclude some elements from taborder.

And of course you can not only set tabindex but also read it:
var ti = someElement.tabIndex;

Jan 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Cezary | last post by:
Hello. I was read PHP manual, but i'm not sure yet. Here is my meta tags in html: <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-2"> <META HTTP-EQUIV="Expires"...
2
by: Jonathan Driller | last post by:
I am attempting to block repeat downloads from a site. I need to have a landing page pass a referer to a secured page. I have tried a meta refresh redirect and several Javascript redirect...
24
by: Day Bird Loft | last post by:
Web Authoring | Meta-Tags The first thing to understand in regard to Meta Tags is the three most important tags placed in the head of your html documents. They are the title, description, and...
9
by: nungon | last post by:
Good morning, I have a web site in which 7 pages repeat once and again in thousands of folders. Why? because I want to keep, to the user view, the pretty url www.myweb.com/username/pageX.asp. ...
3
by: J1C | last post by:
How can I programatically add meta tags with javascript?
3
by: Geoff | last post by:
As a newbie to javascript can someone tell me please how to pass a variable from HTML to Javascript? I have the following script which works OK if I input to str from the "prompt" box, but I want...
3
by: Bill Nguyen | last post by:
I would like to invoke the IE browser and pass values (lat and long) to function GtMap() the html file below from a VB.NET app. help, please! Thanks Bill ------------------------
50
by: Mikhail Teterin | last post by:
Hello! The sample program below is compiled fine by gcc (with -Wall), but rejected by Sun's SUNWspro compiler (version 6 update 2). The point of contention is, whether a value for one of the...
16
by: Edward | last post by:
Hi All, I am having huge problems with a very simple dotnet framework web page (www.gbab.net/ztest3.aspx) , it does NOT render correctly under Apple's Safari. The DIV's do not align amd float as...
2
by: baskar1900 | last post by:
Sir, we are trying to pass chinese character through querystring in ASP and we are using chinese windows 2003 server Operating System. when we tried to retrieve using Request.QueryString () we...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
agi2029
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.