Changing a variable value based on pull down menu value

B

Bob

Is it possible to change the value of a variable
immediately when a different value is selected using a
pulldown menu on a Frontpage form page?

An example would be that pulldown "Item A" needs and
additional amount of cost added to it when selected that
say "Item B" when it is selected. If I can change the
value of a variable value on the fly like this, then I
can easily pass the corrected variable value on as a
hidden field when the form is posted for further
processing. Hope this helps?

Thanks........
 
M

MD Websunlimited

Hi Bob,

If I understand the question, which I'm not sure I do.

<form ....>
<select onchange="this.form.hiddenfield.value = this.options[this.selectedIndex].value;" >
<option value="sasdf">asdfsaf</option>
</select>

When the the drop downs selection changes then the value of the hidden field will change.

--
Mike -- FrontPage MVP '97-'02
J-Bots 2004 102 Components For FP
http://www.websunlimited.com
FrontPage Add-ins Since '97 FP 2003 / 2002 / 2000 Compatible
Download the Trial http://www.microsoft.com/frontpage/downloads/addin/launchupdate/download.asp
 
L

L

When you mention "this.form", what does "this" stand for? "form"?

MD Websunlimited said:
Hi Bob,

If I understand the question, which I'm not sure I do.

<form ....>
<select onchange="this.form.hiddenfield.value = this.options[this.selectedIndex].value;" >
<option value="sasdf">asdfsaf</option>
</select>

When the the drop downs selection changes then the value of the hidden field will change.

--
Mike -- FrontPage MVP '97-'02
J-Bots 2004 102 Components For FP
http://www.websunlimited.com
FrontPage Add-ins Since '97 FP 2003 / 2002 / 2000 Compatible
Download the Trial http://www.microsoft.com/frontpage/downloads/addin/launchupdate/download.asp

Bob said:
Is it possible to change the value of a variable
immediately when a different value is selected using a
pulldown menu on a Frontpage form page?

An example would be that pulldown "Item A" needs and
additional amount of cost added to it when selected that
say "Item B" when it is selected. If I can change the
value of a variable value on the fly like this, then I
can easily pass the corrected variable value on as a
hidden field when the form is posted for further
processing. Hope this helps?

Thanks........
 
K

Kevin Spencer

Any reference to "this" is a self-reference. Look at the object which
contains the reference. In this case it's the <select...> object (HTML
drop-down list box).

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

L said:
When you mention "this.form", what does "this" stand for? "form"?

MD Websunlimited said:
Hi Bob,

If I understand the question, which I'm not sure I do.

<form ....>
<select onchange="this.form.hiddenfield.value =
this.options[this.selectedIndex].value;" >
<option value="sasdf">asdfsaf</option>
</select>

When the the drop downs selection changes then the value of the hidden
field will change.

--
Mike -- FrontPage MVP '97-'02
J-Bots 2004 102 Components For FP
http://www.websunlimited.com
FrontPage Add-ins Since '97 FP 2003 / 2002 / 2000 Compatible
Download the Trial
http://www.microsoft.com/frontpage/downloads/addin/launchupdate/download.asp

Bob said:
Is it possible to change the value of a variable
immediately when a different value is selected using a
pulldown menu on a Frontpage form page?

An example would be that pulldown "Item A" needs and
additional amount of cost added to it when selected that
say "Item B" when it is selected. If I can change the
value of a variable value on the fly like this, then I
can easily pass the corrected variable value on as a
hidden field when the form is posted for further
processing. Hope this helps?

Thanks........
 
L

L

Hi Kevin,

I would like for the field value to be displayed. So instead of having a
hidden field, I want the selected value once changed to display a message.
For example, from the drop down, if the user selects "Microsoft", a field on
the form will display "Microsoft Buisness Solutions selected". Would a
response.write work in this instance?

Kevin Spencer said:
Any reference to "this" is a self-reference. Look at the object which
contains the reference. In this case it's the <select...> object (HTML
drop-down list box).

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

L said:
When you mention "this.form", what does "this" stand for? "form"?

MD Websunlimited said:
Hi Bob,

If I understand the question, which I'm not sure I do.

<form ....>
<select onchange="this.form.hiddenfield.value =
this.options[this.selectedIndex].value;" >
<option value="sasdf">asdfsaf</option>
</select>

When the the drop downs selection changes then the value of the hidden
field will change.

--
Mike -- FrontPage MVP '97-'02
J-Bots 2004 102 Components For FP
http://www.websunlimited.com
FrontPage Add-ins Since '97 FP 2003 / 2002 / 2000 Compatible
Download the Trial
http://www.microsoft.com/frontpage/downloads/addin/launchupdate/download.asp

Is it possible to change the value of a variable
immediately when a different value is selected using a
pulldown menu on a Frontpage form page?

An example would be that pulldown "Item A" needs and
additional amount of cost added to it when selected that
say "Item B" when it is selected. If I can change the
value of a variable value on the fly like this, then I
can easily pass the corrected variable value on as a
hidden field when the form is posted for further
processing. Hope this helps?

Thanks........
 
K

Kevin Spencer

Response.Write is an ASP server-side programming instruction, not a
client-side JavaScript instruction. Mike gave you the syntax for writing a
client-side JavaScript "onchange" event handler. To pop up an alert box, you
would use the JavaScript alert() function. Example:

alert(this.options[this.selectedIndex].value);

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

L said:
Hi Kevin,

I would like for the field value to be displayed. So instead of having a
hidden field, I want the selected value once changed to display a message.
For example, from the drop down, if the user selects "Microsoft", a field
on
the form will display "Microsoft Buisness Solutions selected". Would a
response.write work in this instance?

Kevin Spencer said:
Any reference to "this" is a self-reference. Look at the object which
contains the reference. In this case it's the <select...> object (HTML
drop-down list box).

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

L said:
When you mention "this.form", what does "this" stand for? "form"?

:

Hi Bob,

If I understand the question, which I'm not sure I do.

<form ....>
<select onchange="this.form.hiddenfield.value =
this.options[this.selectedIndex].value;" >
<option value="sasdf">asdfsaf</option>
</select>

When the the drop downs selection changes then the value of the hidden
field will change.

--
Mike -- FrontPage MVP '97-'02
J-Bots 2004 102 Components For FP
http://www.websunlimited.com
FrontPage Add-ins Since '97 FP 2003 / 2002 / 2000 Compatible
Download the Trial
http://www.microsoft.com/frontpage/downloads/addin/launchupdate/download.asp

Is it possible to change the value of a variable
immediately when a different value is selected using a
pulldown menu on a Frontpage form page?

An example would be that pulldown "Item A" needs and
additional amount of cost added to it when selected that
say "Item B" when it is selected. If I can change the
value of a variable value on the fly like this, then I
can easily pass the corrected variable value on as a
hidden field when the form is posted for further
processing. Hope this helps?

Thanks........
 
M

MikeR

This looks like what I've been looking for too. However...
<form....>
<input type="hidden" name="cond">
<select onchange="this.form.cond.value = this.options[this.selectedIndex].value;"
<option value="sasdf">asdfsaf</option>
</select>
doesn't populate "cond" with a value. What did I miss?
MikeR
 
K

Kevin Spencer

Hi MikeR,

You only have one option. The selectedIndex therefore never changes. You
might want to add a "SelectOne" option at the top, and chek that the
selectedIndex is not 0 in your event handler.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

MikeR said:
This looks like what I've been looking for too. However...
<form....>
<input type="hidden" name="cond">
<select onchange="this.form.cond.value =
this.options[this.selectedIndex].value;" <option
value="sasdf">asdfsaf</option>
</select>
doesn't populate "cond" with a value. What did I miss?
MikeR

MD said:
Hi Bob,

If I understand the question, which I'm not sure I do.

<form ....>
<select onchange="this.form.hiddenfield.value =
this.options[this.selectedIndex].value;" >
<option value="sasdf">asdfsaf</option>
</select>

When the the drop downs selection changes then the value of the hidden
field will change.
 
M

MikeR

Thanks Kevin. The actual page has three selections like:
<form....>
<input type="hidden" name="cond">
<select onchange="this.form.cond.value = this.options[this.selectedIndex].value;"
<option value="sasdf">asdfsaf</option>
<option value="sassy">sassy</option>
<option value="drippy">drippy</option>
</select>
I'm a real noob at javascript. When you say event handler, what are you referring
to? How would I check for a zero index?
MikeR
 
K

Kevin Spencer

Hi MikeR,

"onchange" is an event handler for the "onchange" event that is fired by a
select object when the user selects something other than what is already
showing in the sloect object (drop-down list box). You can check for it with
an if statement. Example:

<select onchange="if (this.selectedIndex > 0) this.form.cond.value =
this.options[this.selectedIndex].value;" >

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

MikeR said:
Thanks Kevin. The actual page has three selections like:
<form....>
<input type="hidden" name="cond">
<select onchange="this.form.cond.value =
this.options[this.selectedIndex].value;" <option
value="sasdf">asdfsaf</option>
<option value="sassy">sassy</option>
<option value="drippy">drippy</option>
</select>
I'm a real noob at javascript. When you say event handler, what are you
referring to? How would I check for a zero index?
MikeR

Kevin said:
Hi MikeR,

You only have one option. The selectedIndex therefore never changes. You
might want to add a "SelectOne" option at the top, and chek that the
selectedIndex is not 0 in your event handler.
 
M

MikeR

Thank you. But still no joy. Even this doesn't set the value of the hidden field.
<form....>
<input type="hidden" name="cond">
<select onchange="this.form.cond.value = 'blog';"
<option value="sasdf">asdfsaf</option>
<option value="sassy">sassy</option>
<option value="drippy">drippy</option>
</select>
Also tried it with double quotes around blog.

This is all in loop that writes a table based on a database, so there are 3
identical select/option dropdowns in the form. It that a DOH!! ?

cond does make it to the receiving page as an array (3 elements) of request.form
variables, but all are empty.

MikeR
 
K

Kevin Spencer

Hi MikeR,

Let me share with you a little web programming secret that should help you
to figure this sort of thing out for yourself in the future.

You can debug JavaScript! All you need is Internet Explorer and FrontPage,
which comes with Microsoft Script Debugger.

First, you need to set up Internet Explorer, by going into Tools|Intenet
Options. Click the "Advanced" tab. Find the check box that says "Disable
Script Debugging (Internet Explorer)" and UNcheck it (it is checked by
default). From now on, any JavaScript error will cause IE to ask you if you
want to debug the script in the Debugger. In the Debugger, you can step
through the code one instruction at a time, as well as looking at all of the
HTML elements and JavaScript variables in the page, to examine their state.

In addition, you can put BreakPoints into your JavaScript. A BreakPoint is
an instruction that interrupts the execution and allows you to open the
script in the Debugger. Once you've learned to do these things, you'll be a
JavaScript expert in no time at all.

I checked your code, by creating an HTML page in FrontPage, pasting your
code into it (after fixing it up so that it was syntactically correct, like
taking the ellipsis out of the <form> tag, and adding a </form> tag, but not
changing anything else). Here is what I ran in my Debugger:

<html>

<head>
<base>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body>
<form>
<input type="hidden" name="cond">
<select onchange="debugger;this.form.cond.value = 'blog';">
<option value="sasdf">asdfsaf</option>
<option value="sassy">sassy</option>
<option value="drippy">drippy</option>
</select>
</form>
</body>

</html>

See the "debugger" statement in the select object? That's where it broke
into the debugger. I then executed the next instruction and looked at the
"cond" hidden field value using a QuickWatch. Lo and behold, it had the
value that I selected in it.

Now, you asked me if having more than one form field with the same name
would cause a problem. The answer is, most defintely YES. Of course, now
you're disappointed that you won't be able to use the technique you've been
working on. Take heart, my friend, all is not lost. A little knowledge is a
dangerous thing, so learn all you can about JavaScript if you plan to
continue programming with it. Here's your answer:

When a form submits, it passes the "name" and "value" properties of its form
elements in the Request. That is all. It passes no other properties of its
form elements in the Request. Now, in an HTML document, HTML elements all
have an "id" property. They don't all have a "name" property. Why, you may
ask? Well, I'll tell you. The "id" property is strictly for use on the
client side by CSS and JavaScript.

Is the light coming on now? :)

Now, in JavaScript there is a method that returns ANY HTML element, by
passing its id to the method. To access any HTML element, you simply assign
it an id, and pass that to the function. So, you can have multiple form
fields with the same name, but different ids. It is very important to assign
unique ids to HTML elements for this reason, but not so important to give
them unique names, and in fact, in a case like yours, perhaps a good idea to
give them the same names. The method I'm talking about is
document.getElementById("id"). Here's an example for your problem:

<html>

<head>
<base>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body>
<form>
<input type="hidden" name="cond" id="cond">
<select onchange="document.getElementById("cond").value = 'blog';">
<option value="sasdf">asdfsaf</option>
<option value="sassy">sassy</option>
<option value="drippy">drippy</option>
</select>
</form>
</body>

</html>

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

MikeR said:
Thank you. But still no joy. Even this doesn't set the value of the hidden
field.
<form....>
<input type="hidden" name="cond">
<select onchange="this.form.cond.value = 'blog';"
<option value="sasdf">asdfsaf</option>
<option value="sassy">sassy</option>
<option value="drippy">drippy</option>
</select>
Also tried it with double quotes around blog.

This is all in loop that writes a table based on a database, so there are
3 identical select/option dropdowns in the form. It that a DOH!! ?

cond does make it to the receiving page as an array (3 elements) of
request.form variables, but all are empty.

MikeR

Kevin said:
Hi MikeR,

"onchange" is an event handler for the "onchange" event that is fired by
a select object when the user selects something other than what is
already showing in the sloect object (drop-down list box). You can check
for it with an if statement. Example:

<select onchange="if (this.selectedIndex > 0) this.form.cond.value =
this.options[this.selectedIndex].value;" >
 
L

L

I've tried the following and I get an error message (syntax):
<form>
<input type="hidden" name="cond" id="cond">
<select onchange = "document.getElementById("cond").value ='blog';">
<option value = "Solomon">Solomon</option>
<option value = "Great Plains">Great Plains</option>
<option value = "Axapta">Axapta</option>
</select>

Any ideas?
Kevin Spencer said:
Hi MikeR,

Let me share with you a little web programming secret that should help you
to figure this sort of thing out for yourself in the future.

You can debug JavaScript! All you need is Internet Explorer and FrontPage,
which comes with Microsoft Script Debugger.

First, you need to set up Internet Explorer, by going into Tools|Intenet
Options. Click the "Advanced" tab. Find the check box that says "Disable
Script Debugging (Internet Explorer)" and UNcheck it (it is checked by
default). From now on, any JavaScript error will cause IE to ask you if you
want to debug the script in the Debugger. In the Debugger, you can step
through the code one instruction at a time, as well as looking at all of the
HTML elements and JavaScript variables in the page, to examine their state.

In addition, you can put BreakPoints into your JavaScript. A BreakPoint is
an instruction that interrupts the execution and allows you to open the
script in the Debugger. Once you've learned to do these things, you'll be a
JavaScript expert in no time at all.

I checked your code, by creating an HTML page in FrontPage, pasting your
code into it (after fixing it up so that it was syntactically correct, like
taking the ellipsis out of the <form> tag, and adding a </form> tag, but not
changing anything else). Here is what I ran in my Debugger:

<html>

<head>
<base>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body>
<form>
<input type="hidden" name="cond">
<select onchange="debugger;this.form.cond.value = 'blog';">
<option value="sasdf">asdfsaf</option>
<option value="sassy">sassy</option>
<option value="drippy">drippy</option>
</select>
</form>
</body>

</html>

See the "debugger" statement in the select object? That's where it broke
into the debugger. I then executed the next instruction and looked at the
"cond" hidden field value using a QuickWatch. Lo and behold, it had the
value that I selected in it.

Now, you asked me if having more than one form field with the same name
would cause a problem. The answer is, most defintely YES. Of course, now
you're disappointed that you won't be able to use the technique you've been
working on. Take heart, my friend, all is not lost. A little knowledge is a
dangerous thing, so learn all you can about JavaScript if you plan to
continue programming with it. Here's your answer:

When a form submits, it passes the "name" and "value" properties of its form
elements in the Request. That is all. It passes no other properties of its
form elements in the Request. Now, in an HTML document, HTML elements all
have an "id" property. They don't all have a "name" property. Why, you may
ask? Well, I'll tell you. The "id" property is strictly for use on the
client side by CSS and JavaScript.

Is the light coming on now? :)

Now, in JavaScript there is a method that returns ANY HTML element, by
passing its id to the method. To access any HTML element, you simply assign
it an id, and pass that to the function. So, you can have multiple form
fields with the same name, but different ids. It is very important to assign
unique ids to HTML elements for this reason, but not so important to give
them unique names, and in fact, in a case like yours, perhaps a good idea to
give them the same names. The method I'm talking about is
document.getElementById("id"). Here's an example for your problem:

<html>

<head>
<base>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body>
<form>
<input type="hidden" name="cond" id="cond">
<select onchange="document.getElementById("cond").value = 'blog';">
<option value="sasdf">asdfsaf</option>
<option value="sassy">sassy</option>
<option value="drippy">drippy</option>
</select>
</form>
</body>

</html>

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

MikeR said:
Thank you. But still no joy. Even this doesn't set the value of the hidden
field.
<form....>
<input type="hidden" name="cond">
<select onchange="this.form.cond.value = 'blog';"
<option value="sasdf">asdfsaf</option>
<option value="sassy">sassy</option>
<option value="drippy">drippy</option>
</select>
Also tried it with double quotes around blog.

This is all in loop that writes a table based on a database, so there are
3 identical select/option dropdowns in the form. It that a DOH!! ?

cond does make it to the receiving page as an array (3 elements) of
request.form variables, but all are empty.

MikeR

Kevin said:
Hi MikeR,

"onchange" is an event handler for the "onchange" event that is fired by
a select object when the user selects something other than what is
already showing in the sloect object (drop-down list box). You can check
for it with an if statement. Example:

<select onchange="if (this.selectedIndex > 0) this.form.cond.value =
this.options[this.selectedIndex].value;" >
 
L

L

I figured out the syntax error message. But I want the value to change
to the selected value instead of 'blog'. If they select Solomon, then
Solomon should
be displayed. I'm a newbie at this as well. Here's what I have:
<form>
<input type="text" name="txtProd" id="cond" >
<select onchange = "document.getElementById('cond').value ='blog';">
<option value = "Solomon">Solomon</option>
<option value = "Great Plains">Great Plains</option>
<option value = "Axapta">Axapta</option>
</select>

L said:
I've tried the following and I get an error message (syntax):
<form>
<input type="hidden" name="cond" id="cond">
<select onchange = "document.getElementById("cond").value ='blog';">
<option value = "Solomon">Solomon</option>
<option value = "Great Plains">Great Plains</option>
<option value = "Axapta">Axapta</option>
</select>

Any ideas?
Kevin Spencer said:
Hi MikeR,

Let me share with you a little web programming secret that should help you
to figure this sort of thing out for yourself in the future.

You can debug JavaScript! All you need is Internet Explorer and FrontPage,
which comes with Microsoft Script Debugger.

First, you need to set up Internet Explorer, by going into Tools|Intenet
Options. Click the "Advanced" tab. Find the check box that says "Disable
Script Debugging (Internet Explorer)" and UNcheck it (it is checked by
default). From now on, any JavaScript error will cause IE to ask you if you
want to debug the script in the Debugger. In the Debugger, you can step
through the code one instruction at a time, as well as looking at all of the
HTML elements and JavaScript variables in the page, to examine their state.

In addition, you can put BreakPoints into your JavaScript. A BreakPoint is
an instruction that interrupts the execution and allows you to open the
script in the Debugger. Once you've learned to do these things, you'll be a
JavaScript expert in no time at all.

I checked your code, by creating an HTML page in FrontPage, pasting your
code into it (after fixing it up so that it was syntactically correct, like
taking the ellipsis out of the <form> tag, and adding a </form> tag, but not
changing anything else). Here is what I ran in my Debugger:

<html>

<head>
<base>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body>
<form>
<input type="hidden" name="cond">
<select onchange="debugger;this.form.cond.value = 'blog';">
<option value="sasdf">asdfsaf</option>
<option value="sassy">sassy</option>
<option value="drippy">drippy</option>
</select>
</form>
</body>

</html>

See the "debugger" statement in the select object? That's where it broke
into the debugger. I then executed the next instruction and looked at the
"cond" hidden field value using a QuickWatch. Lo and behold, it had the
value that I selected in it.

Now, you asked me if having more than one form field with the same name
would cause a problem. The answer is, most defintely YES. Of course, now
you're disappointed that you won't be able to use the technique you've been
working on. Take heart, my friend, all is not lost. A little knowledge is a
dangerous thing, so learn all you can about JavaScript if you plan to
continue programming with it. Here's your answer:

When a form submits, it passes the "name" and "value" properties of its form
elements in the Request. That is all. It passes no other properties of its
form elements in the Request. Now, in an HTML document, HTML elements all
have an "id" property. They don't all have a "name" property. Why, you may
ask? Well, I'll tell you. The "id" property is strictly for use on the
client side by CSS and JavaScript.

Is the light coming on now? :)

Now, in JavaScript there is a method that returns ANY HTML element, by
passing its id to the method. To access any HTML element, you simply assign
it an id, and pass that to the function. So, you can have multiple form
fields with the same name, but different ids. It is very important to assign
unique ids to HTML elements for this reason, but not so important to give
them unique names, and in fact, in a case like yours, perhaps a good idea to
give them the same names. The method I'm talking about is
document.getElementById("id"). Here's an example for your problem:

<html>

<head>
<base>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body>
<form>
<input type="hidden" name="cond" id="cond">
<select onchange="document.getElementById("cond").value = 'blog';">
<option value="sasdf">asdfsaf</option>
<option value="sassy">sassy</option>
<option value="drippy">drippy</option>
</select>
</form>
</body>

</html>

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

MikeR said:
Thank you. But still no joy. Even this doesn't set the value of the hidden
field.
<form....>
<input type="hidden" name="cond">
<select onchange="this.form.cond.value = 'blog';"
<option value="sasdf">asdfsaf</option>
<option value="sassy">sassy</option>
<option value="drippy">drippy</option>
</select>
Also tried it with double quotes around blog.

This is all in loop that writes a table based on a database, so there are
3 identical select/option dropdowns in the form. It that a DOH!! ?

cond does make it to the receiving page as an array (3 elements) of
request.form variables, but all are empty.

MikeR

Kevin Spencer wrote:
Hi MikeR,

"onchange" is an event handler for the "onchange" event that is fired by
a select object when the user selects something other than what is
already showing in the sloect object (drop-down list box). You can check
for it with an if statement. Example:

<select onchange="if (this.selectedIndex > 0) this.form.cond.value =
this.options[this.selectedIndex].value;" >
 
M

MikeR

Kevin -
Thanks a bunch! Just what I needed. I just retired after 20+ years as a programmer, but
you can't do this stuff in COBOL ;->. This old brain may be too crowded, but as the COBOL
and CICS drain off, there's hope.
MikeR
 
K

Kevin Spencer

Hi MikeR,

You put "cond" in double quotes, which is exactly what I did in my example!
Sorry! It should be single quotes, as it is inside a double-quoted string.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

L said:
I've tried the following and I get an error message (syntax):
<form>
<input type="hidden" name="cond" id="cond">
<select onchange = "document.getElementById("cond").value ='blog';">
<option value = "Solomon">Solomon</option>
<option value = "Great Plains">Great Plains</option>
<option value = "Axapta">Axapta</option>
</select>

Any ideas?
Kevin Spencer said:
Hi MikeR,

Let me share with you a little web programming secret that should help
you
to figure this sort of thing out for yourself in the future.

You can debug JavaScript! All you need is Internet Explorer and
FrontPage,
which comes with Microsoft Script Debugger.

First, you need to set up Internet Explorer, by going into Tools|Intenet
Options. Click the "Advanced" tab. Find the check box that says "Disable
Script Debugging (Internet Explorer)" and UNcheck it (it is checked by
default). From now on, any JavaScript error will cause IE to ask you if
you
want to debug the script in the Debugger. In the Debugger, you can step
through the code one instruction at a time, as well as looking at all of
the
HTML elements and JavaScript variables in the page, to examine their
state.

In addition, you can put BreakPoints into your JavaScript. A BreakPoint
is
an instruction that interrupts the execution and allows you to open the
script in the Debugger. Once you've learned to do these things, you'll be
a
JavaScript expert in no time at all.

I checked your code, by creating an HTML page in FrontPage, pasting your
code into it (after fixing it up so that it was syntactically correct,
like
taking the ellipsis out of the <form> tag, and adding a </form> tag, but
not
changing anything else). Here is what I ran in my Debugger:

<html>

<head>
<base>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>New Page 1</title>
</head>

<body>
<form>
<input type="hidden" name="cond">
<select onchange="debugger;this.form.cond.value = 'blog';">
<option value="sasdf">asdfsaf</option>
<option value="sassy">sassy</option>
<option value="drippy">drippy</option>
</select>
</form>
</body>

</html>

See the "debugger" statement in the select object? That's where it broke
into the debugger. I then executed the next instruction and looked at the
"cond" hidden field value using a QuickWatch. Lo and behold, it had the
value that I selected in it.

Now, you asked me if having more than one form field with the same name
would cause a problem. The answer is, most defintely YES. Of course, now
you're disappointed that you won't be able to use the technique you've
been
working on. Take heart, my friend, all is not lost. A little knowledge is
a
dangerous thing, so learn all you can about JavaScript if you plan to
continue programming with it. Here's your answer:

When a form submits, it passes the "name" and "value" properties of its
form
elements in the Request. That is all. It passes no other properties of
its
form elements in the Request. Now, in an HTML document, HTML elements all
have an "id" property. They don't all have a "name" property. Why, you
may
ask? Well, I'll tell you. The "id" property is strictly for use on the
client side by CSS and JavaScript.

Is the light coming on now? :)

Now, in JavaScript there is a method that returns ANY HTML element, by
passing its id to the method. To access any HTML element, you simply
assign
it an id, and pass that to the function. So, you can have multiple form
fields with the same name, but different ids. It is very important to
assign
unique ids to HTML elements for this reason, but not so important to give
them unique names, and in fact, in a case like yours, perhaps a good idea
to
give them the same names. The method I'm talking about is
document.getElementById("id"). Here's an example for your problem:

<html>

<head>
<base>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>New Page 1</title>
</head>

<body>
<form>
<input type="hidden" name="cond" id="cond">
<select onchange="document.getElementById("cond").value = 'blog';">
<option value="sasdf">asdfsaf</option>
<option value="sassy">sassy</option>
<option value="drippy">drippy</option>
</select>
</form>
</body>

</html>

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

MikeR said:
Thank you. But still no joy. Even this doesn't set the value of the
hidden
field.
<form....>
<input type="hidden" name="cond">
<select onchange="this.form.cond.value = 'blog';"
<option value="sasdf">asdfsaf</option>
<option value="sassy">sassy</option>
<option value="drippy">drippy</option>
</select>
Also tried it with double quotes around blog.

This is all in loop that writes a table based on a database, so there
are
3 identical select/option dropdowns in the form. It that a DOH!! ?

cond does make it to the receiving page as an array (3 elements) of
request.form variables, but all are empty.

MikeR

Kevin Spencer wrote:
Hi MikeR,

"onchange" is an event handler for the "onchange" event that is fired
by
a select object when the user selects something other than what is
already showing in the sloect object (drop-down list box). You can
check
for it with an if statement. Example:

<select onchange="if (this.selectedIndex > 0) this.form.cond.value =
this.options[this.selectedIndex].value;" >
 
K

Kevin Spencer

Hi L,

"L?" Anyway...

You can reference the Selected option via the options array of the select
object, and using the selectedIndex property. Example:

<form>
<input type="text" name="txtProd" id="cond" >
<select onchange = "document.getElementById('cond').value
=this.options[this.selectedIndex].value;">
<option value = "Solomon">Solomon</option>
<option value = "Great Plains">Great Plains</option>
<option value = "Axapta">Axapta</option>
</select>
</form>

I ran it in a page this time to make sure I got my syntax right! ;-)

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

L said:
I figured out the syntax error message. But I want the value to change
to the selected value instead of 'blog'. If they select Solomon, then
Solomon should
be displayed. I'm a newbie at this as well. Here's what I have:
<form>
<input type="text" name="txtProd" id="cond" >
<select onchange = "document.getElementById('cond').value ='blog';">
<option value = "Solomon">Solomon</option>
<option value = "Great Plains">Great Plains</option>
<option value = "Axapta">Axapta</option>
</select>

L said:
I've tried the following and I get an error message (syntax):
<form>
<input type="hidden" name="cond" id="cond">
<select onchange = "document.getElementById("cond").value ='blog';">
<option value = "Solomon">Solomon</option>
<option value = "Great Plains">Great Plains</option>
<option value = "Axapta">Axapta</option>
</select>

Any ideas?
Kevin Spencer said:
Hi MikeR,

Let me share with you a little web programming secret that should help
you
to figure this sort of thing out for yourself in the future.

You can debug JavaScript! All you need is Internet Explorer and
FrontPage,
which comes with Microsoft Script Debugger.

First, you need to set up Internet Explorer, by going into
Tools|Intenet
Options. Click the "Advanced" tab. Find the check box that says
"Disable
Script Debugging (Internet Explorer)" and UNcheck it (it is checked by
default). From now on, any JavaScript error will cause IE to ask you if
you
want to debug the script in the Debugger. In the Debugger, you can step
through the code one instruction at a time, as well as looking at all
of the
HTML elements and JavaScript variables in the page, to examine their
state.

In addition, you can put BreakPoints into your JavaScript. A BreakPoint
is
an instruction that interrupts the execution and allows you to open the
script in the Debugger. Once you've learned to do these things, you'll
be a
JavaScript expert in no time at all.

I checked your code, by creating an HTML page in FrontPage, pasting
your
code into it (after fixing it up so that it was syntactically correct,
like
taking the ellipsis out of the <form> tag, and adding a </form> tag,
but not
changing anything else). Here is what I ran in my Debugger:

<html>

<head>
<base>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>New Page 1</title>
</head>

<body>
<form>
<input type="hidden" name="cond">
<select onchange="debugger;this.form.cond.value = 'blog';">
<option value="sasdf">asdfsaf</option>
<option value="sassy">sassy</option>
<option value="drippy">drippy</option>
</select>
</form>
</body>

</html>

See the "debugger" statement in the select object? That's where it
broke
into the debugger. I then executed the next instruction and looked at
the
"cond" hidden field value using a QuickWatch. Lo and behold, it had the
value that I selected in it.

Now, you asked me if having more than one form field with the same name
would cause a problem. The answer is, most defintely YES. Of course,
now
you're disappointed that you won't be able to use the technique you've
been
working on. Take heart, my friend, all is not lost. A little knowledge
is a
dangerous thing, so learn all you can about JavaScript if you plan to
continue programming with it. Here's your answer:

When a form submits, it passes the "name" and "value" properties of its
form
elements in the Request. That is all. It passes no other properties of
its
form elements in the Request. Now, in an HTML document, HTML elements
all
have an "id" property. They don't all have a "name" property. Why, you
may
ask? Well, I'll tell you. The "id" property is strictly for use on the
client side by CSS and JavaScript.

Is the light coming on now? :)

Now, in JavaScript there is a method that returns ANY HTML element, by
passing its id to the method. To access any HTML element, you simply
assign
it an id, and pass that to the function. So, you can have multiple form
fields with the same name, but different ids. It is very important to
assign
unique ids to HTML elements for this reason, but not so important to
give
them unique names, and in fact, in a case like yours, perhaps a good
idea to
give them the same names. The method I'm talking about is
document.getElementById("id"). Here's an example for your problem:

<html>

<head>
<base>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>New Page 1</title>
</head>

<body>
<form>
<input type="hidden" name="cond" id="cond">
<select onchange="document.getElementById("cond").value = 'blog';">
<option value="sasdf">asdfsaf</option>
<option value="sassy">sassy</option>
<option value="drippy">drippy</option>
</select>
</form>
</body>

</html>

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

Thank you. But still no joy. Even this doesn't set the value of the
hidden
field.
<form....>
<input type="hidden" name="cond">
<select onchange="this.form.cond.value = 'blog';"
<option value="sasdf">asdfsaf</option>
<option value="sassy">sassy</option>
<option value="drippy">drippy</option>
</select>
Also tried it with double quotes around blog.

This is all in loop that writes a table based on a database, so there
are
3 identical select/option dropdowns in the form. It that a DOH!! ?

cond does make it to the receiving page as an array (3 elements) of
request.form variables, but all are empty.

MikeR

Kevin Spencer wrote:
Hi MikeR,

"onchange" is an event handler for the "onchange" event that is
fired by
a select object when the user selects something other than what is
already showing in the sloect object (drop-down list box). You can
check
for it with an if statement. Example:

<select onchange="if (this.selectedIndex > 0) this.form.cond.value =
this.options[this.selectedIndex].value;" >
 
L

L

Thanks. That worked perfectly.

Kevin Spencer said:
Hi L,

"L?" Anyway...

You can reference the Selected option via the options array of the select
object, and using the selectedIndex property. Example:

<form>
<input type="text" name="txtProd" id="cond" >
<select onchange = "document.getElementById('cond').value
=this.options[this.selectedIndex].value;">
<option value = "Solomon">Solomon</option>
<option value = "Great Plains">Great Plains</option>
<option value = "Axapta">Axapta</option>
</select>
</form>

I ran it in a page this time to make sure I got my syntax right! ;-)

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

L said:
I figured out the syntax error message. But I want the value to change
to the selected value instead of 'blog'. If they select Solomon, then
Solomon should
be displayed. I'm a newbie at this as well. Here's what I have:
<form>
<input type="text" name="txtProd" id="cond" >
<select onchange = "document.getElementById('cond').value ='blog';">
<option value = "Solomon">Solomon</option>
<option value = "Great Plains">Great Plains</option>
<option value = "Axapta">Axapta</option>
</select>

L said:
I've tried the following and I get an error message (syntax):
<form>
<input type="hidden" name="cond" id="cond">
<select onchange = "document.getElementById("cond").value ='blog';">
<option value = "Solomon">Solomon</option>
<option value = "Great Plains">Great Plains</option>
<option value = "Axapta">Axapta</option>
</select>

Any ideas?
:

Hi MikeR,

Let me share with you a little web programming secret that should help
you
to figure this sort of thing out for yourself in the future.

You can debug JavaScript! All you need is Internet Explorer and
FrontPage,
which comes with Microsoft Script Debugger.

First, you need to set up Internet Explorer, by going into
Tools|Intenet
Options. Click the "Advanced" tab. Find the check box that says
"Disable
Script Debugging (Internet Explorer)" and UNcheck it (it is checked by
default). From now on, any JavaScript error will cause IE to ask you if
you
want to debug the script in the Debugger. In the Debugger, you can step
through the code one instruction at a time, as well as looking at all
of the
HTML elements and JavaScript variables in the page, to examine their
state.

In addition, you can put BreakPoints into your JavaScript. A BreakPoint
is
an instruction that interrupts the execution and allows you to open the
script in the Debugger. Once you've learned to do these things, you'll
be a
JavaScript expert in no time at all.

I checked your code, by creating an HTML page in FrontPage, pasting
your
code into it (after fixing it up so that it was syntactically correct,
like
taking the ellipsis out of the <form> tag, and adding a </form> tag,
but not
changing anything else). Here is what I ran in my Debugger:

<html>

<head>
<base>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>New Page 1</title>
</head>

<body>
<form>
<input type="hidden" name="cond">
<select onchange="debugger;this.form.cond.value = 'blog';">
<option value="sasdf">asdfsaf</option>
<option value="sassy">sassy</option>
<option value="drippy">drippy</option>
</select>
</form>
</body>

</html>

See the "debugger" statement in the select object? That's where it
broke
into the debugger. I then executed the next instruction and looked at
the
"cond" hidden field value using a QuickWatch. Lo and behold, it had the
value that I selected in it.

Now, you asked me if having more than one form field with the same name
would cause a problem. The answer is, most defintely YES. Of course,
now
you're disappointed that you won't be able to use the technique you've
been
working on. Take heart, my friend, all is not lost. A little knowledge
is a
dangerous thing, so learn all you can about JavaScript if you plan to
continue programming with it. Here's your answer:

When a form submits, it passes the "name" and "value" properties of its
form
elements in the Request. That is all. It passes no other properties of
its
form elements in the Request. Now, in an HTML document, HTML elements
all
have an "id" property. They don't all have a "name" property. Why, you
may
ask? Well, I'll tell you. The "id" property is strictly for use on the
client side by CSS and JavaScript.

Is the light coming on now? :)

Now, in JavaScript there is a method that returns ANY HTML element, by
passing its id to the method. To access any HTML element, you simply
assign
it an id, and pass that to the function. So, you can have multiple form
fields with the same name, but different ids. It is very important to
assign
unique ids to HTML elements for this reason, but not so important to
give
them unique names, and in fact, in a case like yours, perhaps a good
idea to
give them the same names. The method I'm talking about is
document.getElementById("id"). Here's an example for your problem:

<html>

<head>
<base>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>New Page 1</title>
</head>

<body>
<form>
<input type="hidden" name="cond" id="cond">
<select onchange="document.getElementById("cond").value = 'blog';">
<option value="sasdf">asdfsaf</option>
<option value="sassy">sassy</option>
<option value="drippy">drippy</option>
</select>
</form>
</body>

</html>

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

Thank you. But still no joy. Even this doesn't set the value of the
hidden
field.
<form....>
<input type="hidden" name="cond">
<select onchange="this.form.cond.value = 'blog';"
<option value="sasdf">asdfsaf</option>
<option value="sassy">sassy</option>
<option value="drippy">drippy</option>
</select>
Also tried it with double quotes around blog.

This is all in loop that writes a table based on a database, so there
are
3 identical select/option dropdowns in the form. It that a DOH!! ?

cond does make it to the receiving page as an array (3 elements) of
request.form variables, but all are empty.

MikeR

Kevin Spencer wrote:
Hi MikeR,

"onchange" is an event handler for the "onchange" event that is
fired by
a select object when the user selects something other than what is
already showing in the sloect object (drop-down list box). You can
check
for it with an if statement. Example:

<select onchange="if (this.selectedIndex > 0) this.form.cond.value =
this.options[this.selectedIndex].value;" >
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top