473,545 Members | 2,715 Online
Bytes | Software Development & Data Engineering Community
+ 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.m yvar.value = 2;

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

Dec 11 '05 #1
4 12991
In article <11************ **********@g49g 2000cwa.googleg roups.com>,
el************* @yahoo.com says...
Any tips on how to get this to work?

var myvar = 'sometextfield' ;
document.cost.m yvar.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.FormNa me.FieldName.va lue = 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.m yvar.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.goo glegroups.com.. .
Any tips on how to get this to work?

var myvar = 'sometextfield' ;

--------------------------------------
Maybe the above line should be:
var myvar = document.formNa me.sometextfiel d.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.m yvar.value = 2;


See the group FAQ[1], specifically 4.39.

Mike
[1] <http://www.jibbering.c om/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
9242
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" scrolling="no"> <FRAME src="rundetails.asp" name="rundetails" scrolling="auto"> <FRAME src="rundetailsbottom.asp" name="rundetailsbottom" scrolling="no">...
1
6406
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 is modify the content of one of the textfields prior to it being submitted to the database. Specifically, I need to
1
16614
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 change the value of a text field to the value of the radiobutton--all that works fine! Now, I need to also have it populate a textfield with the...
13
9595
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 assigned to a variable and output using document.write. (Note, there is no submit button or other form elements. Basically
2
3165
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 control does not use any asp.net controls like button or textfield. It uses html "input" for the text field and the button. So after the user has...
3
8892
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) { var str=elm.value; var re = /(-?\d+)(\d{3})(,\d*)?/
1
1928
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: <form> <input type="text" name="textField" size="20"><br> </form> In the "TextField " of Form 1 i type any number and let the number be 100. Now...
2
5463
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 not even put the f into the textbox. However, the TextField does not appear to update until one keypress after I need it to. Eg. if I typed,...
1
1682
by: ujwalkhairnar25 | last post by:
How to give the variable value to textfield on same page?
3
4690
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”)= Request.Form(“First”) %> I also tried: <% Session(“firstname”)= First.Text %>
0
7496
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...
0
7685
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. ...
0
7941
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7784
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...
0
6014
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...
0
5071
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3485
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...
0
3467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1039
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.