473,890 Members | 1,256 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Input type label's value

how to set input type label's value through javascript

Mar 29 '07 #1
4 24457
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

Mar 29 '07 #2
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

Mar 29 '07 #3
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 ?

Mar 29 '07 #4
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

Mar 29 '07 #5

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

Similar topics

6
2489
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>
15
28970
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:
3
2244
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
5
7926
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"
1
4026
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...
0
1120
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.
4
2047
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:
4
17903
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 &nbsp;, like: <input type="checkbox" name="h" value="1" id="chk"/>&nbsp;<label for="chk">Schreibweisentolerant</label> Apparently this doesn't work in Firefox 2. It works in IExplorer and Opera. As well I tried:
1
3238
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...
0
9978
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, 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...
0
9820
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11228
Oralloy
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...
1
10922
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,...
0
10462
tracyyun
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...
0
9630
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, 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...
1
8016
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 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...
0
6041
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4270
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.