473,386 Members | 1,883 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,386 software developers and data experts.

help! user defined objects in a string...

I have been racking my brain out trying to get this to work... (I am
new to javascript)...

Below is what I am trying to accomplish. I want to have the areas with
+txt+ to have the user defined variable inserted. I can't seem to get
it to work.

<html><head>
<script type="text/javascript">
function color(txt)
{
var check = document.formx.i+txt+.value;
if (check=='') {
d+txt+.style.background='#ffffff';
}
else {
d+txt+.style.background='#c0c0c0';
}
}
</script>
</head><body>

<div id="dv1">
Name of vendor: <input type=text name=iv2 disabled
onkeyup="color(v1)"><BR>
</div>

<div id="dv2">
Name of agent: <input type=text name=iv2 disabled
onkeyup="color(v2)"><BR>
</div>

Jul 23 '05 #1
7 1267
gr********@gmail.com wrote:
I have been racking my brain out trying to get this
to work... (I am new to javascript)...

Below is what I am trying to accomplish. I want to
have the areas with +txt+ to have the user defined
variable inserted. I can't seem to get
it to work. <snip> var check = document.formx.i+txt+.value;

<snip>

Look in the FAQ:-

<URL: http://jibbering.com/faq/#FAQ4_39 >

(<URL: http://jibbering.com/faq/faq_notes/square_brackets.html >)

Richard.
Jul 23 '05 #2

Richard Cornford wrote:
gr********@gmail.com wrote:
I have been racking my brain out trying to get this
to work... (I am new to javascript)...

Below is what I am trying to accomplish. I want to
have the areas with +txt+ to have the user defined
variable inserted. I can't seem to get
it to work.

<snip>
var check = document.formx.i+txt+.value;

<snip>

Look in the FAQ:-

<URL: http://jibbering.com/faq/#FAQ4_39 >

(<URL: http://jibbering.com/faq/faq_notes/square_brackets.html >)

Richard.

Hmm... I tried it like the FAQ said, but still no luck. Would you mind
posting a working version of the code I posted? It keeps saying object
undefined.

Jul 23 '05 #3
On 29/03/2005 22:18, gr********@gmail.com wrote:

[snip]
<URL: http://jibbering.com/faq/faq_notes/square_brackets.html >
Hmm... I tried it like the FAQ said, but still no luck.


Presumably you haven't changed your function calls so that you're
passing string literals not identifiers.

onkeyup="color(v1)"

The script engine will be trying to find - and failing, too - a
variable named v1. Quote it with single quotes.
Would you mind posting a working version of the code I posted?


An example might be in order as there are other issues.

1) You seem to be trying to use the id attribute values of the
two DIV elements as global variables. Don't. That's nonsense
introduced by Microsoft that you'd do well to avoid.
2) Disabling a form control in the mark-up itself is not
something you should do in any environment where you cannot
guarantee script support. Namely, the Web. If you're going to
need a script to enable something, or show something, you
should also use a script to disable or hide that thing in the
first place.
3) You can avoid worrying about the name or id attributes of
elements by passing a reference to the function and using the
DOM to access those element according to their structural
relationship. The example below demonstrates this.

It would seem that you're trying to colour around controls which have
values. A nicer approach than using DIVs would be to use LABELs. If
necessary, you can always make them block-level (using the a "display:
block" declaration in your style sheet) if need be. Also, if you want
some padding underneath the controls, use padding not a forced line break.

function highlight(control) {var colour, label;
/* Control is a reference to the form control.
* If its value is not an empty string, use a
* light grey...
*/
if(control.value) {colour = '#c0c0c0';}
/* ...otherwise use white. */
else {colour = '#ffffff';}

/* If we can obtain a reference to the parent node (the
* LABEL element), and that node has a style object...
*/
if((label = control.parentNode) && label.style) {
/* ...set the background colour to the previously
* determined colour.
*/
label.style.backgroundColor = colour;
}
}
<label>Name of vendor:
<input type="text" name="iv1" onkeyup="highlight(this);">
</label>

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #4
gr********@gmail.com wrote:
Richard Cornford wrote:
gr********@gmail.com wrote: <snip>
... . I want to
have the areas with +txt+ to have the user defined
variable inserted. I can't seem to get
it to work.<snip>
var check = document.formx.i+txt+.value;

<snip>

Look in the FAQ:-

<URL: http://jibbering.com/faq/#FAQ4_39 >

<snip> Hmm... I tried it like the FAQ said, but still no luck.
Luck is not a factor in computer programming.
Would you mind posting a working version of the code I
posted? It keeps saying object undefined.


That is very unlikely to be what it actually says. But it is in the
nature of computers that specific conditions produce specific error
messages. Those error messages may all seem vague and indistinct at
first but we have seen enough of them to be able to deduce a great deal
from them, given the _exact_ wording (and knowledge of the nature of the
system producing those errors).

That is not how it works. If I post complete code that does what you
appear to want all that will happen is that you will come back looking
for copulate code to solve your next problem. If, on the other hand, we
promote an understanding of whatever you are doing wrong, or
misunderstanding, then you will be in a position to solve your own
problems, and may eventually be in a position to provide assistance to
others.

If you have tried to implement a version of your code that uses
appropriate bracket notation property accessors to allow the dynamic
construction of property names and the result does not work then you
have either erred, or misunderstood. What you now do is post that code
and someone will (may[1]) tell you what you have done wrong, and/or
attempt to explain and correct your misconception(s).

Richard.

[1] It is impossible to guarantee that any post will get a response, and
many shoot themselves in the foot by disregarding Usenet conventions or
failing to fully read the FAQ before asking questions. Both can be
avoided.
Jul 23 '05 #5
Thank you so much for your help! Actually seeing the code helped so
much, because I was able to actually see what works, and use that
information along with what I know about what doesn't work.

Really appreciate it.

Thanks to Richard as well for the words on education within the
community.

Jul 23 '05 #6
Lee
Richard Cornford said:
That is not how it works. If I post complete code that does what you
appear to want all that will happen is that you will come back looking
for copulate code to solve your next problem.


Problem with the spell checker, or some sort of censorship filter?

Jul 23 '05 #7
Lee wrote:
Richard Cornford said:
That is not how it works. If I post complete code that does
what you appear to want all that will happen is that you will
come back looking for copulate code to solve your next problem.


Problem with the spell checker, or some sort of censorship filter?


:) Spell checker. I have corrections while I type turned off on my
user account to prevent Word from doing just that sort of stupid thing
with my otherwise bad spelling and typos, but I was logged on as an
administrator at the time and Word is not configured as I would like
with that account.

Richard.
Jul 23 '05 #8

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

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
9
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with...
4
by: Sarir Khamsi | last post by:
Is there a way to get help the way you get it from the Python interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the module cmd.Cmd? I know how to add commands and help text to...
6
by: d.warnermurray | last post by:
I am doing a project for school that involves creating help files for a html authoring tool. If you could help me with answers to some questions it would really help. 1. What tasks do you expect...
7
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
5
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time...
9
by: JJ | last post by:
Do you all use HTML help workshop to create your help system. I am finding it quite clumsy to use. Mayeb because I am not used to using it. Do any of you use any other techniques to create help...
4
by: Fred Flintstone | last post by:
This one baffles me. I'm using VS.Net 2005 and write desktop apps that need built in help. So logically, I figure maybe VS has a help system component built in so I search the help. Hey! ...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
1
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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:
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...

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.