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

process form var

Please give this code a look. I'm not a JS programmer at all, but I
can't figure out why identical lines in essentially the same context
work in one place but in the other, it causes the entire interface to
disappear.

This is for a tabbed interface, and I'm just trying to pass the
options_total value around among the JS fxns. I get no error output in
the Javascript Console ... just a blank screen without tabs, panels, or
forms.

Working code: called with the line

updateOptionsTotal({$optionset_id},{$productoption _id},this.form)
function updateOptionsTotal(set_id,new_option_id,form) {
former_option_id = selected_options[set_id];
selected_options[set_id] = new_option_id;

options_total=eval(form.options_total.value);

....

Breaking: (called with the line:
writeTabPanel(this.form);
function writeTabPanel(form){
var tpText = '';
tpText += '<div id="';
tpText += this.tab.id;
tpText += '" class="tab" style="top:';
tpText += this.tab.top;
tpText += ';left:';
tpText += this.tab.left;
tpText += ';width:';
tpText += this.tab.width;
tpText += '" onClick="showPanel(\'';
tpText += this.tab.id + '\',\'' + this.panel.id;
options_total = eval(form.options_total.value);
....
If I comment out this last line, everything works great -- except that
the value obviously isn't passed.
Oct 6 '05 #1
12 1755
Lee
Matthew Crouch said:

Please give this code a look. I'm not a JS programmer at all, but I
can't figure out why identical lines in essentially the same context
work in one place but in the other, it causes the entire interface to
disappear.

This is for a tabbed interface, and I'm just trying to pass the
options_total value around among the JS fxns. I get no error output in
the Javascript Console ... just a blank screen without tabs, panels, or
forms.

Working code: called with the line

updateOptionsTotal({$optionset_id},{$productoptio n_id},this.form)
function updateOptionsTotal(set_id,new_option_id,form) {
former_option_id = selected_options[set_id];
selected_options[set_id] = new_option_id;

options_total=eval(form.options_total.value);

...

Breaking: (called with the line:
writeTabPanel(this.form);
function writeTabPanel(form){
var tpText = '';
tpText += '<div id="';
tpText += this.tab.id;
tpText += '" class="tab" style="top:';
tpText += this.tab.top;
tpText += ';left:';
tpText += this.tab.left;
tpText += ';width:';
tpText += this.tab.width;
tpText += '" onClick="showPanel(\'';
tpText += this.tab.id + '\',\'' + this.panel.id;
options_total = eval(form.options_total.value);
...
If I comment out this last line, everything works great -- except that
the value obviously isn't passed.


Using eval() on two different values isn't even close to doing the same thing
twice. What sort of value are you expecting, and why are you executing text
entered by the user?

Oct 6 '05 #2
Lee wrote:
Matthew Crouch said:
Please give this code a look. I'm not a JS programmer at all, but I
can't figure out why identical lines in essentially the same context
work in one place but in the other, it causes the entire interface to
disappear.

This is for a tabbed interface, and I'm just trying to pass the
options_total value around among the JS fxns. I get no error output in
the Javascript Console ... just a blank screen without tabs, panels, or
forms.

Working code: called with the line

updateOptionsTotal({$optionset_id},{$productopti on_id},this.form)
function updateOptionsTotal(set_id,new_option_id,form) {
former_option_id = selected_options[set_id];
selected_options[set_id] = new_option_id;

options_total=eval(form.options_total.value);

...

Breaking: (called with the line:
writeTabPanel(this.form);
function writeTabPanel(form){
var tpText = '';
tpText += '<div id="';
tpText += this.tab.id;
tpText += '" class="tab" style="top:';
tpText += this.tab.top;
tpText += ';left:';
tpText += this.tab.left;
tpText += ';width:';
tpText += this.tab.width;
tpText += '" onClick="showPanel(\'';
tpText += this.tab.id + '\',\'' + this.panel.id;
options_total = eval(form.options_total.value);
...
If I comment out this last line, everything works great -- except that
the value obviously isn't passed.

Using eval() on two different values isn't even close to doing the same thing
twice. What sort of value are you expecting, and why are you executing text
entered by the user?

This is a basic shopping cart thingy, and the items have options, etc.
that carry an "upcharge". options_total is the sum of all these
upcharges. the first fxn, updateOptionsTotal, is successfully changing
this sum to reflect a change in selections (radio buttons) on the form.

Does that clarify?

Does eval() execute code and not evaluate it? Like I said, the first fxn
seems to be working fine.
Oct 6 '05 #3
Lee
Matthew Crouch said:

Lee wrote:
Matthew Crouch said:
Please give this code a look. I'm not a JS programmer at all, but I
can't figure out why identical lines in essentially the same context
work in one place but in the other, it causes the entire interface to
disappear.

This is for a tabbed interface, and I'm just trying to pass the
options_total value around among the JS fxns. I get no error output in
the Javascript Console ... just a blank screen without tabs, panels, or
forms.

Working code: called with the line

updateOptionsTotal({$optionset_id},{$productopt ion_id},this.form)
function updateOptionsTotal(set_id,new_option_id,form) {
former_option_id = selected_options[set_id];
selected_options[set_id] = new_option_id;

options_total=eval(form.options_total.value);

...

Breaking: (called with the line:
writeTabPanel(this.form);
function writeTabPanel(form){
var tpText = '';
tpText += '<div id="';
tpText += this.tab.id;
tpText += '" class="tab" style="top:';
tpText += this.tab.top;
tpText += ';left:';
tpText += this.tab.left;
tpText += ';width:';
tpText += this.tab.width;
tpText += '" onClick="showPanel(\'';
tpText += this.tab.id + '\',\'' + this.panel.id;
options_total = eval(form.options_total.value);
...
If I comment out this last line, everything works great -- except that
the value obviously isn't passed.

Using eval() on two different values isn't even close to doing the same thing
twice. What sort of value are you expecting, and why are you executing text
entered by the user?

This is a basic shopping cart thingy, and the items have options, etc.
that carry an "upcharge". options_total is the sum of all these
upcharges. the first fxn, updateOptionsTotal, is successfully changing
this sum to reflect a change in selections (radio buttons) on the form.

Does that clarify?

Does eval() execute code and not evaluate it? Like I said, the first fxn
seems to be working fine.


The eval() method evaluates the string argument as a Javascript expression.
In other words, it compiles and executes it. That's a very dangerous thing to
do with user input. If you just want the numeric value of the options_total
field, use:

options_total = +form.options_total.value;

Oct 6 '05 #4
Lee wrote:
Matthew Crouch said:
Lee wrote:
Matthew Crouch said:
Please give this code a look. I'm not a JS programmer at all, but I
can't figure out why identical lines in essentially the same context
work in one place but in the other, it causes the entire interface to
disappear.

This is for a tabbed interface, and I'm just trying to pass the
options_total value around among the JS fxns. I get no error output in
the Javascript Console ... just a blank screen without tabs, panels, or
forms.

Working code: called with the line

updateOptionsTotal({$optionset_id},{$productop tion_id},this.form)
function updateOptionsTotal(set_id,new_option_id,form) {
former_option_id = selected_options[set_id];
selected_options[set_id] = new_option_id;

options_total=eval(form.options_total.value);

...

Breaking: (called with the line:
writeTabPanel(this.form);
function writeTabPanel(form){
var tpText = '';
tpText += '<div id="';
tpText += this.tab.id;
tpText += '" class="tab" style="top:';
tpText += this.tab.top;
tpText += ';left:';
tpText += this.tab.left;
tpText += ';width:';
tpText += this.tab.width;
tpText += '" onClick="showPanel(\'';
tpText += this.tab.id + '\',\'' + this.panel.id;
options_total = eval(form.options_total.value);
...
If I comment out this last line, everything works great -- except that
the value obviously isn't passed.
Using eval() on two different values isn't even close to doing the same thing
twice. What sort of value are you expecting, and why are you executing text
entered by the user?


This is a basic shopping cart thingy, and the items have options, etc.
that carry an "upcharge". options_total is the sum of all these
upcharges. the first fxn, updateOptionsTotal, is successfully changing
this sum to reflect a change in selections (radio buttons) on the form.

Does that clarify?

Does eval() execute code and not evaluate it? Like I said, the first fxn
seems to be working fine.

The eval() method evaluates the string argument as a Javascript expression.
In other words, it compiles and executes it. That's a very dangerous thing to
do with user input. If you just want the numeric value of the options_total
field, use:

options_total = +form.options_total.value;

Thanks. I haven't seen the syntax with the plus-sign before, but I'm
using an old book. What exactly does it mean?
Oct 6 '05 #5
Matthew Crouch wrote:
[snip}

options_total = +form.options_total.value;

Thanks. I haven't seen the syntax with the plus-sign before, but I'm
using an old book. What exactly does it mean?


same as:
options_total = Number(form.options_total.value);

Converts a string to a number, if possible.

Mick
Oct 6 '05 #6
Matthew Crouch wrote:
<snip>
Does eval() execute code and not evaluate it?
What does the documentation for - eval - say? But how would you expect
javascript source code to be evaluated except by executing it?
Like I
said, the first fxn seems to be working fine.


What an - eval - call does is entirely determined by the value passed as
the argument to the function call, and the result can be, literally,
anything. If the argument is a variable, or a value provided externally,
looking at the actual - eval - call tells you nothing about what is
happening. It is this aspect of - eval - that makes it particularly hard
to debug code that uses it, and one of the many reasons that the use
of - eval - is strongly discouraged by informed javascript authors
(combined with the observation that it is almost never necessary to
use - eval - ).

Richard.
Oct 6 '05 #7


The eval() method evaluates the string argument as a Javascript expression.
In other words, it compiles and executes it. That's a very dangerous thing to
do with user input. If you just want the numeric value of the options_total
field, use:

options_total = +form.options_total.value;


This gives me the same result: no output
Oct 7 '05 #8

updateOptionsTotal({$optionset_id},{$productop tion_id},this.form)
function updateOptionsTotal(set_id,new_option_id,form) {
former_option_id = selected_options[set_id];
selected_options[set_id] = new_option_id;

options_total=eval(form.options_total.value); changed to
options_total = +form.options_total.value;

works fine, i.e. as before

...

Breaking: (called with the line:
writeTabPanel(this.form);
function writeTabPanel(form){
var tpText = '';
tpText += '<div id="';
tpText += this.tab.id;
tpText += '" class="tab" style="top:';
tpText += this.tab.top;
tpText += ';left:';
tpText += this.tab.left;
tpText += ';width:';
tpText += this.tab.width;
tpText += '" onClick="showPanel(\'';
tpText += this.tab.id + '\',\'' + this.panel.id;
options_total = eval(form.options_total.value);


changed to
options_total = +form.options_total.value;

Same problem. Other ideas?
Oct 7 '05 #9
On 06/10/2005 21:29, Matthew Crouch wrote:

[snip]
options_total = eval(form.options_total.value);
...
If I comment out this last line, everything works great -- except that
the value obviously isn't passed.


You're expecting us to fix code that you haven't shown. Furthermore,
you've provided little in the way of a description: we don't know what
is supposed to happen, what does happen, and why the observed behaviour
is unacceptable.

Please post a URL to an example (minimised, if possible) and a decent
description of the issue so that readers can help you properly.

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Oct 7 '05 #10
Michael Winter wrote:
On 06/10/2005 21:29, Matthew Crouch wrote:

[snip]
options_total = eval(form.options_total.value);
...
If I comment out this last line, everything works great -- except that
the value obviously isn't passed.

You're expecting us to fix code that you haven't shown. Furthermore,
you've provided little in the way of a description: we don't know what
is supposed to happen, what does happen, and why the observed behaviour
is unacceptable.

Please post a URL to an example (minimised, if possible) and a decent
description of the issue so that readers can help you properly.

Mike


The interface can be previewed here:
http://phc-online.com/phc1.12/store/...product_id=111

what i'm trying to accomplish is that the "options" and "total" values
persist as you change tabs (from "appearance" to "construction"). My
present strategy is to have the onclick for those radio buttons include
the current total...

view the source of that big inline frame (with the form inside) and the
applicable JS is near the top.

the panels and tabs drawing functions are in
http://www.phc-online.com/phc1.12/js...opTabbedUI2.js

there are other scripts involved. it's kinda complicated. i'm trying to
learn a few basic techniques; i hope you don't think i'm trying to make
you do my code.

Thanks again,
M
Oct 7 '05 #11
On 07/10/2005 20:26, Matthew Crouch wrote:
The interface can be previewed here:
http://phc-online.com/phc1.12/store/...product_id=111


You need to review how to access form controls[1]. You should also make
write consistent code: sometimes you access controls via a form object
(though only once using the reference you pass), but other times you try
to use the name attribute value like a global. If you must do one, do
the former; the latter is nonsense[2].

Preferably, you should use the forms and elements collections, and save
references to these to minimise the number of property accesses.

function updateOptionsTotal(set, option, form) {
var elem = form.elements,
optionsTotal = +elem.options_total.value
- options[selected_options[set]]
+ options[option],
total = +elem.base_price.value + optionsTotal;

elem.options_total.value = optionsTotal;
elem.grand_total.value = total;
elem.info.value = 'Total: ' + total;
}

function totalonly(optionsTotal, form) {
form.elements.options_total.value = optionsTotal;
}

You should also review the markup generated server-side. It mixes XHTML
and HTML (use the latter, only) and generates invalid markup (there's
more than one HTML, HEAD and BODY element). There might be other errors,
too.

[snip]

Mike
[1] <URL:http://www.jibbering.com/faq/faq_notes/form_access.html>
[2] It's something that Microsoft seemed to introduce. Don't use it
as relatively few browsers support it.

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Oct 7 '05 #12
Michael Winter wrote:
On 07/10/2005 20:26, Matthew Crouch wrote:
The interface can be previewed here:
http://phc-online.com/phc1.12/store/...product_id=111

You need to review how to access form controls[1]. You should also make
write consistent code: sometimes you access controls via a form object
(though only once using the reference you pass), but other times you try
to use the name attribute value like a global. If you must do one, do
the former; the latter is nonsense[2].

Preferably, you should use the forms and elements collections, and save
references to these to minimise the number of property accesses.

function updateOptionsTotal(set, option, form) {
var elem = form.elements,
optionsTotal = +elem.options_total.value
- options[selected_options[set]]
+ options[option],
total = +elem.base_price.value + optionsTotal;

elem.options_total.value = optionsTotal;
elem.grand_total.value = total;
elem.info.value = 'Total: ' + total;
}

function totalonly(optionsTotal, form) {
form.elements.options_total.value = optionsTotal;
}

You should also review the markup generated server-side. It mixes XHTML
and HTML (use the latter, only) and generates invalid markup (there's
more than one HTML, HEAD and BODY element). There might be other errors,
too.

[snip]

Mike
[1] <URL:http://www.jibbering.com/faq/faq_notes/form_access.html>
[2] It's something that Microsoft seemed to introduce. Don't use it
as relatively few browsers support it.

I appreciate all this. Was hesitant to even show the code, since as you
noticed it's cobbled together from assorted tutorials.

I'm the PHP guy on this project, and I should learn better JS. But I
wonder if you could clean this up for a fee, as I need to get this out
the door and don't have time to study up just now.

Email me if interested. "spamless" shouldn't be in the address, of course.

Matt
Oct 8 '05 #13

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

Similar topics

2
by: RL | last post by:
Hello Perl gurus, 1. I have a web page where I can push a button (dospawn.html). 2. This button calls a CGI script (spawnboss.cgi) 3. spawnboss.cgi calls a forking perl script (forkme.pl) 4....
3
by: Andreas | last post by:
Hi, I just created my first vb.net pocket pc application - that consists of a main dialog and an additional dialog that is defined globally like this: Dim x as New MyTestDialog As the...
1
by: Mullin Yu | last post by:
But, I want is that I can have a Main app that will start a new process or kill one particular or all process. The process will open a console exe. But, I don't want the user to close the console...
0
by: hzgt9b | last post by:
Using VB .NET 2003, I am having problems with a windows application that I have written: Here's the situation. The application I created has a main form that has its TopMost property set to True...
1
by: PraveenKadkol | last post by:
Hi, My question : If my process is taking more than 30 mins to complete, then i need to send out email to all the users. I have two forms, 1 is "Main form" and another is dummy form, dummy...
13
by: Edwin Smith | last post by:
I have a form which displays a DataGridView table generated with the VS2005 tools. The database is a Pervasive v.9 with an ODBC driver. The DataGridView works great except when I'm done and I...
3
by: SugarDaddy | last post by:
Here's my problem. I have an NT service (really a .NET service) running as local system. I have a .NET form running on the user account. The form and the service communicate via an IPC Channel...
4
by: =?Utf-8?B?UmljaA==?= | last post by:
On a form - I have a datagridview which is docked to the entire form. The datagridview allows users to Delete and/or Add Rows. On the Form_Load event I Fill the datagridview source table with a...
3
by: sewid | last post by:
Hi! I have a very simple windows form (Visual Basic, .NET-Framework 2.0). This is my whole code: Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As...
32
by: John Wright | last post by:
I have a long process I run that needs to be complete before the user can continue. I can change the cursor to an hourglass, but I want to update the Status Strip on the bottom during the process. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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...
0
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
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
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...
0
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...

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.