473,480 Members | 2,347 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using variable to set a textfield value

Any tips on how to get this to work?

var myvar = 'sometextfield';
document.cost.myvar.value = 2;

It keeps saying myvar is null or not an object even though
'sometextfield' has a value.

Dec 11 '05 #1
4 12987
In article <11**********************@g49g2000cwa.googlegroups .com>,
el*************@yahoo.com says...
Any tips on how to get this to work?

var myvar = 'sometextfield';
document.cost.myvar.value = 2;

It keeps saying myvar is null or not an object even though
'sometextfield' has a value.


Do you have a form called "cost" and a field element called "myvar"?
Looks to me like you've got it arse about face, going on the code you've
given. To set a form field's value, just do

document.FormName.FieldName.value = jsVariable;

You could also use getElementById, but start with the easy way.

--

Hywel
http://kibo.org.uk/
Dec 11 '05 #2
el*************@yahoo.com wrote:
Any tips on how to get this to work?

var myvar = 'sometextfield';
document.cost.myvar.value = 2;

It keeps saying myvar is null or not an object even though
'sometextfield' has a value.


document.cost[myvar].value = 2;
It's covered in the FAQ:

<URL: http://www.jibbering.com/faq/#FAQ4_39 >
--
Rob
Dec 11 '05 #3

<el*************@yahoo.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Any tips on how to get this to work?

var myvar = 'sometextfield';

--------------------------------------
Maybe the above line should be:
var myvar = document.formName.sometextfield.value;
Or
var myvar = document.forms[0].sometextfield.value;
(assuming the first form contains your sometextfield)

hth
hr
Dec 11 '05 #4
On 11/12/2005 22:16, el*************@yahoo.com wrote:
Any tips on how to get this to work?

var myvar = 'sometextfield';
document.cost.myvar.value = 2;


See the group FAQ[1], specifically 4.39.

Mike
[1] <http://www.jibbering.com/faq/>

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Dec 11 '05 #5

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

Similar topics

4
9240
by: Kathryn | last post by:
I hope you can help as this is driving me crazy! I have an asp which has 3 frames on it as follows: <FRAMESET rows="50%,*,10%"> <FRAME src="rundetailstop.asp" name="rundetailstop"...
1
6389
by: Veverita | last post by:
Hi there I'm hoping that someone can help me with a question I have about javascript syntax. I got an html page that uploads an image and some text field to a database. What I'd like to do...
1
16602
by: LRW | last post by:
Below is some of the code I'm using. I have a PHP page generating a list of items. I've made it so that each one has a radiobutton with a unique value. You can click on the radiobutton and it will...
13
9580
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
2
3162
by: kplkumar | last post by:
I have created a asp.net date picker control using Javascript. I wanted to do this to avoid doing post back when the calendar window is launched. It works like charm. But the challenge is - the...
3
8882
by: Cah Sableng | last post by:
Hi all. I am new member of this group. I have a problem with currency formatter function I made. On onkeyup's method of a textfield I add function below: <snip> function formatCurrency(elm)...
1
1915
by: macintoshhondo | last post by:
Hi ! i am a newbie and dont know javascript much. what i really need is a simple javascript code that can insert number in the value section of the different forms from the one form. FORM 1:...
2
5453
jkmyoung
by: jkmyoung | last post by:
I was trying to create an applet with a TextField that would only accept an integer, and ignore any other keystrokes. Eg, if a user typed in an 'f' into the field, the TextField should ignore it, and...
1
1678
by: ujwalkhairnar25 | last post by:
How to give the variable value to textfield on same page?
3
4688
PLA2000
by: PLA2000 | last post by:
I want to store a value that I enter in a textfield in a session variable to use on another page without submitting the value to a data table. I tried: <% Session(“firstname”)=...
0
7054
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,...
0
7097
jinu1996
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...
0
5353
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,...
1
4794
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...
0
4493
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2993
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1307
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 ...
1
567
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
193
bsmnconsultancy
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...

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.