473,396 Members | 1,990 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.

Passing form id in FF 3.6 vs. FF 4.01

Claus Mygind
571 512MB
My form broke when we upgraded from FireFox 3.6 to FireFox 4.01

I use an onchange event handler on my select control. In that handler I pass a reference to the control "this".

In the 2nd code snippet from my javaScript, I extract a reference to the parent form from "this".

In FF 3.6 I could use this reference: "var oForm = obj.form.id;". But in FF 4.01 the "form"returns a null. How come? and what do I need to pass that reference or can I read that reference some other way from "this" that will work in both FF 3.6 and 4.01?

Expand|Select|Wrap|Line Numbers
  1. <body>
  2.  <form METHOD="POST" 
  3.        Action="my.exe"
  4.     ENCTYPE="application/x-www-form-urlencoded"
  5.          NAME="EditTimeForm"
  6.          id  ="EditTimeForm">
  7.  
  8.  
  9.    <select name="regHRS"   onChange="NoPTOorOff(this,'line1','Yes')">
  10.  
  11.  </form>
  12. </body>
  13.  
Expand|Select|Wrap|Line Numbers
  1. function NoPTOorOff(obj, cLine, cTravel) 
  2. {                               
  3.  var objV = obj.value;          
  4.  var oForm = obj.form.id; 
  5. document.forms[oForm].elements[cLine+"OFF"];
  6. }                                                        
Jun 16 '11 #1

✓ answered by Claus Mygind

Thanks Dormilich for sticking with me on this issue.

I finally got it figured out. It was not a javaScript issue nor was it an HTML issue.

I have two forms an "AddTime" and an "EditTime" form. Both apps are written in dBase. The server executes the app and streams the webpage page and associated javaScript file back to the client via the dBase script.

I checked the "AddTime" app which called the same exact function and it worked just fine.

The only difference I noticed between the two pages was the delimiter used by dBase to wrap the HTML code. dBase allows you to delimit the HTML code with ' " or [

On the older app "AddTime" my code was wrapped with the single quote ' and the slightly newer (but still old) "EditTime", I wrapped the code with the square brackets [ ]

And for whatever reason, when the page was sent to FF 4 client the reference on the select control to the "form" was lost. FF 4 reported the "obj.form" as null (that is what you see in the image), whereas the image for FF 3.6 still showed the link.

I have a lot of other code wrapped with the [ ] that still works fine in FF 4, so there must have been some other little troll hiding in there.

Faulty code
Expand|Select|Wrap|Line Numbers
  1.    puts([<BODY ])
  2.    puts([ <FORM METHOD="POST" ])
  3.    puts([         ENCTYPE="application/x-www-form-urlencoded"])
  4.    puts([         NAME="EditTimeForm"])
  5.    puts([         id  ="EditTimeForm">])
  6.  
Fixed code
Expand|Select|Wrap|Line Numbers
  1.    puts('<BODY>')
  2.    puts(' <FORM METHOD="POST" ')
  3.    puts('       ENCTYPE="application/x-www-form-urlencoded"')
  4.    puts('        NAME="EditTimeForm"')
  5.    puts('        id  ="EditTimeForm">')
  6.  
Sometimes I do wish I had a way to demo a page. But I am working on an intranet, so I have no means of displaying a working app.

Again, I cannot thank you enough for your help. I continue to learn a lot from you

11 2110
Claus Mygind
571 512MB
I think I need the reference to the form because I interact with other controls on the same line in the form. If time is added or subtracted that will affect what amount of time is permitted in the other selects and check boxes etc.

here is a snap shot of the other controls when only one line is displayed (the form can contain multiple lines)

Jun 16 '11 #2
Claus Mygind
571 512MB
I have now even tried to pass "this.form" and it still does not work with these lines.
Expand|Select|Wrap|Line Numbers
  1. <select id ="HRS" name="HRS" onChange="NoPTOorOff(this,'line1','yes', this.form););">
  2.  
  3. function NoPTOorOff(obj, cLine, cTravel, oForm) 
  4.  
Here "oForm" is still null.
Jun 16 '11 #3
Dormilich
8,658 Expert Mod 8TB
what is the function NoPTOorOff() supposed to do?
Jun 16 '11 #4
Claus Mygind
571 512MB
This is a time sheet. the javascript functions keep track of various types of time earned by the employee. Check and balances are in place so excess time cannot be entered by the user.

Here is what the edit screen looks like.



this is the add screen



both the edit screen add screen use the same functions however, I call a sub function from "NoPTOorOff" called "adjustPersBal"

In the adjustPersBal() function, I look to see which screen made the call to the function (see below). Also as you can see, I have several other functions that use the same reference. I was hoping not to have to re-write everything right now as I am involved in a larger re-write of all my apps moving from one language to another (php). So the more I can keep the same for now the better, especially when it comes to the client side of the apps.



Expand|Select|Wrap|Line Numbers
  1. function NoPTOorOff(obj, cLine, cTravel, oForm) 
  2. {                               
  3. /* var objV = obj.value;          
  4.  var oForm = obj.form.id; 
  5.  var timOff = document.forms[oForm].elements[cLine+"OFF"];
  6.  var persnl = document.forms[oForm].elements[cLine+"PERS"];
  7.  var regHrs = document.forms[oForm].elements[cLine+"HRS"];
  8.  if (objV != "" && document.forms[oForm].elements[cLine+"OFF"] ) {              
  9.    timOff.checked = false;
  10.    //update current balance of personal time
  11.    adjustPersBal(persnl, cLine, oForm)
  12.    persnl.value   = "0";        
  13.  }                                                                                
  14. */
  15.  var objV = obj.value;          
  16.  var timOff = document.getElementById(cLine+"OFF") ;
  17.  var persnl = document.getElementById(cLine+"PERS");
  18.  var regHrs = document.getElementById(cLine+"HRS");
  19.  if (objV != "" && document.getElementById(cLine+"OFF")) {              
  20.    timOff.checked = false;
  21.    //update current balance of personal time
  22.    adjustPersBal(persnl, cLine, oForm)
  23.    persnl.value   = "0";        
  24.  }                                                                                
  25. }                                                                                        
  26.  
  27. function AdjustReg(obj, cLine, cDOW) 
  28. {                               
  29.  if (cDOW!="1" && cDOW!="7")
  30.  {
  31.      var oForm = obj.form.id; 
  32.      var valRegHrs = parseFloat(document.forms[oForm].elements[cLine+"HRS"].value);
  33.      var valPwHrs  = parseFloat(document.forms[oForm].elements[cLine+"PWREG"].value);
  34.      var valPwHrs2 = parseFloat(document.forms[oForm].elements[cLine+"PWREG2"].value);
  35.      var cTotHrs = valRegHrs+valPwHrs+valPwHrs2
  36.      if (cTotHrs > 8) {             
  37.        alert("The sum of the Regular Hours, Prevailing Wage and Prevailing Wage 2 hours exceed 8 hrs!"+'\n'+"Please adjust.")
  38.         document.forms[oForm].elements[cLine+"HRS"].value = "0";
  39.         document.forms[oForm].elements[cLine+"PWREG"].value ="0";
  40.         document.forms[oForm].elements[cLine+"PWREG2"].value ="0";
  41.      }                                                                                
  42.  }
  43.  
  44. }                                                                                        
  45.  
  46. function showThisWeek( cPrev, cLocation)  
  47. {                    
  48.    location="/SMNO/addTimeOneWeek.exe?StartDate=" + cPrev + "&LOCATION=" + escape(cLocation) + "&EMPNO=yes";
  49. }                                                                             
  50. function adjustPersBal(obj, cLine, oForm)
  51. {
  52.    if (obj.value == "8" || obj.value == "8.00")
  53.    {
  54.     //calculate new Personal Time value based on change.
  55.      if (oForm == "EditTimeForm" )
  56.      {
  57.         var xVal    = parseFloat(document.getElementById("PTOHOURS").value);
  58.         var oVal     = xVal+8;
  59.         //hidden balance field used to update balance in employee file found only in addTimeOneWeek
  60.         document.getElementById("PTOHOURS").value = oVal.toString();
  61.         document.getElementById("persHrBal").innerHTML = oVal.toString();
  62.      }else{
  63.         var xVal    = parseFloat(document.getElementById(cLine+"PERSBal").innerHTML);
  64.         var oVal     = xVal+8;
  65.         document.getElementById(cLine+"PERSBal").innerHTML = oVal.toString();
  66.      }
  67.      if (oForm == "AddTimeOneWeekForm")
  68.      {
  69.         var cCnt = cLine.substring(0,4)
  70.         for (var i = 2; i < 7; i++ )
  71.         {
  72.             document.getElementById(cCnt+i+"PERSBal").innerHTML = oVal.toString();
  73.         }
  74.         //hidden balance field used to update balance in employee file found only in addTimeOneWeek
  75.         document.getElementById("PTOHOURS").value = oVal.toString();
  76.      }
  77.  
  78.    }
  79. }
  80.  
Jun 16 '11 #5
Dormilich
8,658 Expert Mod 8TB
first of all, the parameter oForms is wasted, you can access it via obj.form.

line #4 is also off, as forms are not called by ID, but by name or number (and we all know that IDs must not be numbers).

even then, if you have the form, why using document.form_name? i.e.
Expand|Select|Wrap|Line Numbers
  1. var timOff = obj.form.elements[cLine+"OFF"];
personally I’d use an object that already stores the cLine and cTravel values. then you can easily move to an external JS file.
Jun 16 '11 #6
Claus Mygind
571 512MB
I added oForm as a parameter after my first post in an attempt to capture the name of the form when FF 4 would not return the id from "var oForm = obj.form.id;". As you can see I have left my original code in the /* */ section. I adjusted one "select" control to send that parameter also via "this.form", but that did not work either.

Please note that all my ids are alpahnumeric. I currently generate the line like this: "wkLineName = ltrim(str(wkLineCount))+'X'+c["EMPNODATE"].value"

This is dBase code, but should not look too unfamiliar to you. Note the first part of the string is number converted to a string and trimmed. That I then add a separator "X" and then tack on another string made up of the employee id and record date. That makes the content of that line and it's controls unique from all other records.

I just tried your suggestion "document.form_name" and that came back as undefined.

Also note I had this code running since 2004. So my coding may not have been as good at that time.

I might agree with your suggestion about the obj, but again I am trying to minimize the amount of re-write I have to do.

So I would really like to know how I can add a reference to the form to each of the select controls on the line (see my image in my second post). Prior to FF 4, I could pass the value simply by making a parameter "this". Since "this" is an object it carried the reference to the parent where I used it to extract it in the javascript function with this code "var oForm = obj.form.id;". This no longer works in FF 4

Thanks again for all your help. It is very much appreciated.
Jun 16 '11 #7
Dormilich
8,658 Expert Mod 8TB
as I already said, form access does not work with the ID. IDs are only useful in combination with document.getElementById().

hint: document.form_name = document["form_name"] = document.forms["form_name"], i.e. dot-notation can’t use variables

PS. personally I’ve given up on inline JS since I learned of EventTarget.addEventListener()
Jun 16 '11 #8
Claus Mygind
571 512MB
I totally agree with you about the inline js. And also thanks for the clarification on form_name point.

And when I get to this point in my re-write, I will make the necessary upgrades. At this time I was only looking for a small fix to keep the app running.

The main question I guess I have here is the app as it sits still works in FF 3.6.

<select name="regHRS" onChange="NoPTOorOff(this,'line1','Yes')">

passing a reference to the select object with the reserved word "this", In FF 3.6 I was able to reference all it's properties and attributes, including the id of the form on which the control was located.

function NoPTOorOff(obj, cLine, cTravel)
{
var oForm = obj.form.id;
}

Now in FF 4 that info is no longer provided. See the two screen shots below of exactly the same code.

FF 3.6



FF 4

Jun 21 '11 #9
Dormilich
8,658 Expert Mod 8TB
not sure what you mean. in both pictures (right side) you see that obj is a <select> element (despite the many property additions in FF4).

EDIT: looked up at HTML5 and found this:
A form-associated element can have a relationship with a form element, which is called the element's form owner. If a form-associated element is not associated with a form element, its form owner is said to be null.
from the looks of it, there is no form associated, but hard to tell without HTML code (usual question, do you have a demo page?)
Jun 21 '11 #10
Claus Mygind
571 512MB
Thanks Dormilich for sticking with me on this issue.

I finally got it figured out. It was not a javaScript issue nor was it an HTML issue.

I have two forms an "AddTime" and an "EditTime" form. Both apps are written in dBase. The server executes the app and streams the webpage page and associated javaScript file back to the client via the dBase script.

I checked the "AddTime" app which called the same exact function and it worked just fine.

The only difference I noticed between the two pages was the delimiter used by dBase to wrap the HTML code. dBase allows you to delimit the HTML code with ' " or [

On the older app "AddTime" my code was wrapped with the single quote ' and the slightly newer (but still old) "EditTime", I wrapped the code with the square brackets [ ]

And for whatever reason, when the page was sent to FF 4 client the reference on the select control to the "form" was lost. FF 4 reported the "obj.form" as null (that is what you see in the image), whereas the image for FF 3.6 still showed the link.

I have a lot of other code wrapped with the [ ] that still works fine in FF 4, so there must have been some other little troll hiding in there.

Faulty code
Expand|Select|Wrap|Line Numbers
  1.    puts([<BODY ])
  2.    puts([ <FORM METHOD="POST" ])
  3.    puts([         ENCTYPE="application/x-www-form-urlencoded"])
  4.    puts([         NAME="EditTimeForm"])
  5.    puts([         id  ="EditTimeForm">])
  6.  
Fixed code
Expand|Select|Wrap|Line Numbers
  1.    puts('<BODY>')
  2.    puts(' <FORM METHOD="POST" ')
  3.    puts('       ENCTYPE="application/x-www-form-urlencoded"')
  4.    puts('        NAME="EditTimeForm"')
  5.    puts('        id  ="EditTimeForm">')
  6.  
Sometimes I do wish I had a way to demo a page. But I am working on an intranet, so I have no means of displaying a working app.

Again, I cannot thank you enough for your help. I continue to learn a lot from you
Jun 21 '11 #11
Dormilich
8,658 Expert Mod 8TB
Sometimes I do wish I had a way to demo a page. But I am working on an intranet, so I have no means of displaying a working app.
File > save page as … > website - HTML only / website - complete

may not be a fully operable app, but good enough for HTML/JavaSctipt issues (without postback/AJAX)
Jun 21 '11 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Kevin Lyons | last post by:
Hello, I am trying to get all of my form elements passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html to the following URL:...
2
by: sindre | last post by:
Hi, I have a form with many fields. And then I thought I could have two other forms similar but here is only the submit button visible. What I want is: if the user click on a submit button on a...
3
by: Abby Lee | last post by:
My code works but because I'm using VBscript within JavaScript I get an error message...the yellow tri-angle with an "!" mark. ---------------within my body------------- <script...
3
by: SV | last post by:
Dear all, In my application I have a lot of hidden fields. I want to make them invisible for the users though for debugging reasons I want to make them visible. So I want to add these objects to...
4
by: Ron Rohrssen | last post by:
I want to show a dialog and when the form (dialog) is closed, return to the calling form. The calling form should then be able to pass the child form to another object with the form as a...
4
by: Miguel Dias Moura | last post by:
Hello, i created an ASP.net / VB page with a really big form. Now i want to create 4 pages and in each one i will place 1/4 of the big form. The last page will send all the form values by...
1
by: williamroy | last post by:
Hello, I've got a form that runs over 5 pages. I need the last page submit button to post all of the answers at one time from the previous 5 pages (to another server). I'd like to see the last...
10
by: patelxxx | last post by:
Problem: I am trying to input my name in a text box and I click on transfer and I want the name to appear on the same page (i.e. in another form). How is this done? <BODY> <HTML> <form...
5
by: jmartmem | last post by:
Greetings, I have built an Update Record Form in an ASP page. This form contains a number of fields, such as text boxes and menus, to name a few. Upon clicking the 'submit' button, I want the...
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?
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
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
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...
0
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,...

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.