how to set input type label's value through javascript 4 24448
On Mar 29, 1:08 am, "pradeep" <pwprad...@gmai l.comwrote:
how to set input type label's value through javascript
assuming "in" is input element and "newVal" is new value for label.
var labels=document .getElementsByT agName("label") ,i;
for( i=0; i<labels.length ;i++ )
if(labels[i].htmlFor==in.id )labels[i].innerHTML=newV al
--
will be easy if you just set an id on label and the use getElementById
On Mar 29, 5:23 pm, "scripts.contac t" <scripts.cont.. .@gmail.com>
wrote:
On Mar 29, 1:08 am, "pradeep" <pwprad...@gmai l.comwrote:
how to set input type label's value through javascript
assuming "in" is input element and "newVal" is new value for label.
Javascript has an "in" operator, so not a good choice for a local
variable.
The W3C HTML specification doesn't define a value attribute for label
elements, so assigning a value attribute to a label and giving it a
value may be unreliable for whatever (undisclosed) purpose the OP has
in mind.
>
var labels=document .getElementsByT agName("label") ,i;
for( i=0; i<labels.length ;i++ )
if(labels[i].htmlFor==in.id )labels[i].innerHTML=newV al
The for attribute is not mandatory, the label can be related to an
input by being its parent:
<label><input ... ></label>
is quite valid, though IE doesn't correctly associate the label with
the input so not recommended.
will be easy if you just set an id on label and the use getElementById
I guess you're suggesting something like a scheme that assigns a label
id which is the same as the input id or name with a prefix of "label",
e.g.:
<label id="label_i01"> <input name="i01"></label>
Then the label id can be used to find the input id or name and hence
get a reference to the appropriate element. However, also be aware
that a label can be associated with more than one control, any
solution should accommodate that.
--
Rob
On Mar 29, 3:29 am, "RobG" <r...@iinet.net .auwrote:
var labels=document .getElementsByT agName("label") ,i;
for( i=0; i<labels.length ;i++ )
if(labels[i].htmlFor==in.id )labels[i].innerHTML=newV al
The for attribute is not mandatory, the label can be related to an
input by being its parent:
so this should work-
function getLabel(iElem) {
if(/label/i.test(iElem.pa rentElement.tag Name))
return iElem.parentEle ment
var labels=document .getElementsByT agName("label") ,i;
for( i=0; i<labels.length ;i++ ){
if(labels[i].htmlFor==iElem .id)
return labels[i]
}
return false
}
will be easy if you just set an id on label and the use getElementById
I guess you're suggesting something like a scheme that assigns a label
id which is the same as the input id or name with a prefix of "label",
e.g.:
<label id="label_i01"> <input name="i01"></label>
Then the label id can be used to find the input id or name and hence
get a reference to the appropriate element.
yes.
However, also be aware
that a label can be associated with more than one control, any
solution should accommodate that.
How ? like this :
<label >
Name : <input type="text">
Pass : <input type="password" >
</label>
but it will work for first control only, right ?
On Mar 29, 9:41 pm, "scripts.contac t" <scripts.cont.. .@gmail.com>
wrote:
On Mar 29, 3:29 am, "RobG" <r...@iinet.net .auwrote:
[...]
However, also be aware
that a label can be associated with more than one control, any
solution should accommodate that.
How ? like this :
<label >
Name : <input type="text">
Pass : <input type="password" >
</label>
Yes.
>
but it will work for first control only, right ?
Clicking on the second control should put focus on the first. I
should also have said that the for attribute associates a label with
exactly one control, but that a control can have more than one label -
I assume so you can layout forms without splitting labels over block
elements, e.g. (wrapped for posting):
<form action="">
<table>
<tr>
<td style="text-align:right;">< label
for="foo">Ipsum </label></td>
<td><label for="foo">Lorem </label></td>
<td><input type="text" id="foo" name="foo"></td>
</tr>
<tr>
<td style="text-align:right;">< label
for="bar">seque stor</label></td>
<td><label for="bar">ce</label></td>
<td><input type="text" id="bar" name="bar"></td>
</tr>
<tr>
<td colspan="3"><la bel>Multi<input name="b1">
<input name="b2"></label></td>
</tr>
</table>
</form>
Probably a bad example, but hopefully it does the job - it "works" in
Firefox, can't say what IE will make of it. Probably best to follow-
up in an HTML group. :-)
--
Rob This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Boyd Reilly |
last post by:
I have a form that has the user pick the type of question he will answer.
The input field will be a text, numeric or date type. So, after the
question is answered, I need to change the input statement. This resembles
what I am doing:
<form name="frm1">
Step 1 - Choose a File: <select name="selA" OnChange="makeinputbox;"
width="200" style="width:200">
<option value="">Date of Birth</option>
<option value="MASTER">Age</option>
|
by: Mattia |
last post by:
Hi!
I have a <form> that can be submitted thruogh three buttons and I need
to tell witch one was pressed when the form was submitted. I now do it
with 3 <input type="submit" name="..." value="...">
with <input type="submit" ...> the only name-value values submitted
(pushed into the query string) is the one of the submit button that was
pushed (if you have many of them).
Ex:
|
by: leeaids |
last post by:
Hi,
I am hoping somebody can help me.
Normally to use the file upload feature in an html page, users must
either select or type in a file to upload then click on button or link
to initiate the upload. I was wondering if it were possible to put a
default file name in?
Thanks
|
by: Mark Woodward |
last post by:
Hi all,
I'm trying to set up a 'control panel' consisting of a table of icons.
The early stages: http://www.deepinit.com/controlcentre.php
Each of these is set up like:
<td>
<input type="image" id="addnews" src="/Image/add24.png"
|
by: spolsky |
last post by:
try the the following code with Opera 9.01 (Windows). when clicked
slightly faster than normal clicking, the toggler checkbox and other
checkboxes displays differently although event method works fine to
update the checkboxes. there is not any problem with IE 6 or FireFox
1.5. also, i used the double click event method to see if its the
source but that does not help even. Opera 9.01 seems to be slow at
updating checkboxes visually. am i...
| |
by: Rotsey |
last post by:
Hi,
I have a application that fills a html hidden control with xml serverside.
I use javascript to read the value of the control on the client.
The problem is the value property is blank when using Firefox, ok in IE6.
When I view the page source with Firefox I see the control and xml.
|
by: stevewy |
last post by:
If I am using srcElement (or "target" for non-IE models) to return
various properties of an object I have clicked on, can I access for
"label for" value in any way? I'm thinking, for example, of an input
text box like this:
<label for="fred">Username:</label>
<input type="text" name="hello" id="hello1" size="10">
Now, once a function has:
|
by: ckirchho |
last post by:
Hallo,
In a form I have several text or checkbox inputs with their
appropriate labels. I'd like to keep label and input together, so I
connect them with a , like:
<input type="checkbox" name="h" value="1" id="chk"/> <label
for="chk">Schreibweisentolerant</label>
Apparently this doesn't work in Firefox 2. It works in IExplorer and
Opera. As well I tried:
|
by: mishrarajesh44 |
last post by:
hi all,
i am writting a program to update the record in the mysql databqse, using php.
I hav designed the 'update form' totally same as my 'add form' so that by entering
the mobile no. of the desired person , i will get back the update form having all fields as in add form and all field having the corresponding retrived value..
but how will show the image name that was saved in the database in the photo field..
Is
<input type=file...
|
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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: 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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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: 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...
| |