473,789 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

form variable not being set

i've written some javascript code that i believe should set a form
variable to a certain value, depending on what the user clicks on.
unfortunately, it isn't working. here's the url:

http://www.frostjedi.com/terra/scripts/graemlin3.html

clicking in the color palette thing and then clicking the submit button
reveals that the form variable named color isn't being set. if you
look at the javascript source, you'll see that i'm atleast attempting
to set it with "document.f orms[0].color.value = 'xxxxxx'"...

any ideas on what i'm doing wrong and how i could go about fixing it
would be appreciated - thanks!

Jul 23 '05 #1
10 1770
A job for 'alert', I'd say.

"yawnmoth" <te*******@yaho o.com> wrote in message
news:11******** **************@ l41g2000cwc.goo glegroups.com.. .
i've written some javascript code that i believe should set a form
variable to a certain value, depending on what the user clicks on.
unfortunately, it isn't working. here's the url:

http://www.frostjedi.com/terra/scripts/graemlin3.html

clicking in the color palette thing and then clicking the submit button
reveals that the form variable named color isn't being set. if you
look at the javascript source, you'll see that i'm atleast attempting
to set it with "document.f orms[0].color.value = 'xxxxxx'"...

any ideas on what i'm doing wrong and how i could go about fixing it
would be appreciated - thanks!

Jul 23 '05 #2
In article <11************ **********@l41g 2000cwc.googleg roups.com>,
"yawnmoth" <te*******@yaho o.com> wrote:
clicking in the color palette thing and then clicking the submit button
reveals that the form variable named color isn't being set. if you
look at the javascript source, you'll see that i'm atleast attempting
to set it with "document.f orms[0].color.value = 'xxxxxx'"...


Trim this down to just the color pane and the javascript.

Implement you own debug console so you can print out progress data.
see:
http://groups-beta.google.com/group/...t/msg/170ddb0d...
Here is an example of how to work with an input field.

Robert

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Simple validate</title>

<script type="text/javascript">

function myfunction(form Name,formField)
{

var ok;
var newValue = document.forms[formName].elements[formField].value;
alert('formName = ' + formName +
' formField = ' + formField +
' value = ' + newValue);

if( /^(0|[1-9]\d*)$/.test(newValue) )
{
var theValue = parseInt(newVal ue,10) + 1;
document.forms[formName].elements[formField].value = theValue;
ok = true;
}
else
{ ok = false;
alert('You need to enter a number.')
}

return ok;
}
</script>
</head>
<body>
<p>
The HTML file demonstrates how increment an input field.
Please input a number. </p>
<p>
</p>
<form name="myForm"
action="http://www.natAValidWe bAddress.com"
method="POST"
onsubmit="retur n myfunction('myF orm','theAddres s');">

<p>Address:&nbs p;
<input type="text" name="theAddres s" id='theAddress' size="40"></p>
<br>
<input type="submit" value="Submit address information">
</form>
</body>
</html>
Jul 23 '05 #3
yawnmoth wrote:
i've written some javascript code that i believe should set a form
variable to a certain value, depending on what the user clicks on.
unfortunately, it isn't working. here's the url:

http://www.frostjedi.com/terra/scripts/graemlin3.html

clicking in the color palette thing and then clicking the submit button reveals that the form variable named color isn't being set. if you
look at the javascript source, you'll see that i'm atleast attempting
to set it with "document.f orms[0].color.value = 'xxxxxx'"...

any ideas on what i'm doing wrong and how i could go about fixing it
would be appreciated - thanks!


Simple problem...the color values being generated by the 'colorSwatch'
function don't match the select values in the 'color' listbox. So
nothing gets selected. Probably the most logical way to proceed here is
to reconstruct the listbox at the same time you're 'replacing' it with
the palette, ensuring the values match. Roughly....
function colorSwatch(wid th, height)
{
............
............
document.getEle mentById('color ').style.displa y = 'none';
extra = '';
var sel = document.forms[0].color; //get listbox
sel.options.len gth = 0; //clear it
............
............
for(b = 0; b < 5; b++) {
temp = "" + numberList[r] + "" + numberList[g] + "" + numberList[b];
sel.options[sel.options.len gth] = new Option(temp, temp);
document.writel n('<a href="javascrip t:void........
............
............
}

Cute little app. \:=)

Jul 23 '05 #4
RobB wrote:
[...]
var sel = document.forms[0].color; //get listbox
sel.options.len gth = 0; //clear it


AFAIK, this will only work in IE because length is supposed to
be read-only. Surely the options should be removed using DOM
to remove the nodes, then add the new ones?

[...]

--
Rob
Jul 23 '05 #5

RobB wrote:
yawnmoth wrote:
<snip>

Simple problem...the color values being generated by the 'colorSwatch' function don't match the select values in the 'color' listbox. So
nothing gets selected. Probably the most logical way to proceed here is to reconstruct the listbox at the same time you're 'replacing' it with the palette, ensuring the values match. Roughly.... <snip code>
that makes sense. thanks for the tip / code! :)

as per RobG's comment... i found a website that i should be able to
reference for making it more cross-browser compliant (i'm mostly just
posting it for my personal reference):

http://www.mredkj.com/tutorials/tutorial005.html
Cute little app. \:=)


thanks! :=)

Jul 23 '05 #6
yawnmoth wrote:
RobB wrote:
yawnmoth wrote:
<snip>

Simple problem...the color values being generated by the 'colorSwatch'
function don't match the select values in the 'color' listbox. So
nothing gets selected. Probably the most logical way to proceed here is
to reconstruct the listbox at the same time you're 'replacing' it with
the palette, ensuring the values match. Roughly....

<snip code>


that makes sense. thanks for the tip / code! :)


Your'e welcome.
as per RobG's comment...


Don't sweat it.

http://www.faqts.com/knowledge_base/...d/1600/fid/178
Cute little app. \:=)


thanks! :=)


NP.

Jul 23 '05 #7
RobB wrote:
[...]
as per RobG's comment...


Don't sweat it.

http://www.faqts.com/knowledge_base/...d/1600/fid/178


Since select.length is the same as select.options. length, why not
use:

select.length = 0;

Saves an entire 8 keystrokes. You can also use it to add options:

selectRef.lengt h += 10;

will add 10 empty options.
Seems my understanding re length being read only is out of date
(in regard to arrays and collections anyway). Since about
JavaScript 1.1:

"You can set the length property to truncate an array at
any time. When you extend an array by changing its length
property, the number of actual elements does not increase..."

<URL:http://synchro.net/docs/js/ref/array.html#1193 439>

Sun had some similar comments on options collections.

I could not find any reference on the W3C site to say that the
number of options can be modified by changing the length other
than this in their "issues to be resolved":

"From O'Reilly's JavaScript Definitive Guide book [p. 646]:

"[begin quote]

"If you set an element in the options[] array to null, then
that option will be removed from the Select object, and the
elements above it in the array will be moved down, changing
their indices, to occupy the new space in the array.

"If you create a new Option object with the Option()
constructor (see the Option reference entry), you can add that
option to the end of list of options in the Select object by
assigning the newly created option to a position at the end of
the options[] array. To do this, set options[options.length].

"[end quote]

"Additional ly, if you set options.length to a value higher than
the current value, then the number of options in the Select
object will be increased by adding new options to the end of
the array.

"Each of the browsers that I tested, Netscape, Win IE, Mac IE,
and WebTV, all work as above. I tested older versions of
browsers as well as the latest versions of these browsers."

<URL:http://www.w3.org/2001/12/DOM-Level-2-issues#i9b>

So I guess use length to modify arrays/collections all you like,
you should be able to extend and truncate arrays this way and can
use select.length or select.options. length (tested in IE and
Firefox).

--
Rob
Jul 23 '05 #8
RobG wrote:

[snip]
I could not find any reference on the W3C site to say that the
number of options can be modified by changing the length other
than this in their "issues to be resolved":


So I take it you didn't read the DOM 2 HTML Specification
(<URL:http://www.w3.org/TR/DOM-Level-2-HTML>) then? :P

From Appendix D - ECMAScript Language Binding:

Objects that implement the HTMLOptionsColl ection interface:
Properties of objects that implement the HTMLOptionsColl ection
interface:
length
This property is a Number and can raise an object that
implements DOMException interface on setting.

[Note that it doesn't say "read-only" in the description.]

Objects that implement the HTMLSelectEleme nt interface:
Properties of objects that implement the HTMLSelectEleme nt
interface:
length
This property is a Number and can raise an object that
implements DOMException interface on setting.

[Again, no "read-only".]

From Appendix A.1.1 - Changes to DOM Level 1 interfaces and exceptions:

Interface HTMLSelectEleme nt
The type of the attribute options was changed from HTMLCollection
to HTMLOptionsColl ection.
The attribute length is no longer readonly and is now unsigned.

[The length property of the HTMLCollection interface in both versions
/is/ read-only, so the change is significant.]

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #9
Michael Winter wrote:
RobG wrote:

[snip]
I could not find any reference on the W3C site to say that the
number of options can be modified by changing the length other
than this in their "issues to be resolved":

So I take it you didn't read the DOM 2 HTML Specification
(<URL:http://www.w3.org/TR/DOM-Level-2-HTML>) then? :P


Not, strictly speaking, in its entirety. But the point is kinda
moot since I'm not sure that had I done so I would have inferred
that I could use length to add and delete elements from an
options collection anyway. :-(

[...]
[Note that it doesn't say "read-only" in the description.] [...] [Again, no "read-only".]


But it does say the length attribute of HTMLCollection is
read-only. To me, it would be handy if at that point the spec
pointed out that there are exceptions to the rule.

Noted of course that for HTMLOptionsColl ection, length
"specifies the length or size of the list."

I can't find anywhere in the spec that says something like
"length can be used to change the number of elements in an
options collection".

Clearly I don't think laterally enough! ;-)
--
Rob
Jul 23 '05 #10

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

Similar topics

1
7436
by: Newbie | last post by:
OK, this may be impossible since I'm using 3rd party shopping cart ASP software, but I've been able to finagle a lot of other stuff I thought wouldn't work, so here we go: I'm using a form in which users enter numbers to be calculated into a square footage cost. Upon submitting, the results page uses ASP to give the total and the chance to add the new totalled item to the cart or try a new calculation. Part of the cart's software has a...
13
74140
by: genetic.error | last post by:
I'm moving from Vb6 to VB.Net. I have a feeling this has come up before... The VS.Net MSDN file seems to state that the following should work: Form1.Show Form1.Visible = True Form1.Hide Form1.Visible = False Load (Form1)
7
6424
by: rickcheney | last post by:
I just changed my Access 2002 database to a SQL Server ADP project. I had a form where the user entered a value into a text box and when a command button on the form was clicked a Report was opened. The reports record source is a query. The query uses the value from the form text box to restrict the query. Table name = EggsTable one of the columns in the table is named: EggColor Form name = EggColorForm Form text box name = ColorTextBox
12
3238
by: (Pete Cresswell) | last post by:
I know I can open many instances of a given form, but I've never done it. Now I'm analyzing an application where that seems like just the ticket: Many investment funds, *lots* of data points for each fund, and a desire by the users to see several funds presented side-by-side. Is opening, say, five instances of the same form real-world-doable? -- PeteCresswell
21
1777
by: Just Me | last post by:
I've tried in a few places using a variable name Form and it appears to be OK. For example: Public Shared Sub WritePositionsInRegistry(ByVal Form As Form, ByVal SubkeyName As String) Is it OK to use a Type name as a variable name. For example,: Set(ByVal Color As Color)
6
6336
by: Leszek | last post by:
Hi. I wrote a script: function zmiana(ile){ while(document.getElementById('accomp').childNodes.length>1){ ostatni=document.getElementById('document.dane.accomp').lastChild; document.getElementById('document.dane.accomp').removeChild(ostatni);
7
3390
by: Terry | last post by:
I have a Mainform with a Statusbar. When opening another form or doing some processing I want to display info in the Statusbar of the Mainform. I have read a lot of articles on this & have come up with the code below. It seems to work(!!!) in that when coding the second form I can see the DisplayStatusMsg of the main form. During debug the code runs through & seemingly executes the call without error. But!...The message is not displayed....
3
6183
by: hermand | last post by:
I've got an online job application I am building using ASP/VBScript. The application consists of one ASP document which has three separate states. States: 1. Form Display 2. Form Review (takes all information submitted from the first form state and removes the form elements and displays entered information using "Response.form()".
4
2635
by: Greg Scharlemann | last post by:
I'm trying to setup a dyamic dropdown list that displays a number of text fields based on the selected number in the dropdown. The problem I am running into is capturing the data already entered before the list is repopulated. For example, suppose the user selects 3 in the drop down list and 3 text fields are shown. If the user populates the 3 text fields with data and decides to change the drop down to a list of 4 or 5, how do I capture...
12
2371
by: Rob | last post by:
Let's say you open Form1 that contains TabControl1 There are several tabs on TabControl1 Now you open a new Form2 that contains a User Control How can you determine the Selected tab in Form1 from the User Control in Form2 ? Hope this is clear enough...
0
9666
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
9511
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
10199
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10139
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
9983
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
9020
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...
0
6769
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3700
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.