Chris__T
Posts: 339
|
Posted: 05/13/2008, 8:47 AM |
|
Quote :How to access control values.
Sometimes you may need to loop through an editable grid’s rows and modify or print control values. You can access those values using the following code:
init<form_name>Elements();
for(var j = 0; j < <form_name>Elements.length; j++){
alert('TextBox value:' + <form_name>Elements[j][<form_name><textbox_name>ID].value +
', ListBox value:' +
<form_name>Elements[j][<form_name<listbox_name>ID].value +
', ListBox displayed text' + <form_name>Elements[j][<form_name><listbox_name>ID].options
[<form_name>Elements[j][<form_name><lustbox_name>ID].selectedIndex].text);
}
I used the above from Nicole's tips and solutions page http://forums.codecharge.com/posts.php?post_id=60507 to try and deal with putting a value in an editable grid control, and then when that control loses focus (onblur event), to calculate value*1.5 and stick that new value into the control. It's for Comp Time. If the user enters "2" into the Comp_hours box, then when they leave the box, it should change to "3". So I used her code above to modify for my page:
function comptime(){
for(var j = 0; j < Employee2Elements.length; j++){
Empployee2Elements[j][Employee2Comp_hoursID].value = Employee2Elements[j][Employee2Comp_hoursID].value *1.5;
}
}
Then in the html is the onblur for the control: onblur="javascript:comptime()"
I think I'm on the right track, but have a feeling I'm not wrapping my brain around this correctly.
|
|
|
wkempees
Posts: 1679
|
Posted: 05/13/2008, 9:19 AM |
|
Empployee
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
|
|
Chris__T
Posts: 339
|
Posted: 05/13/2008, 10:47 AM |
|
Thanks. Always nice to have different sets of eyes take a look at code. However, that didn't fix the problem. Technically, it should change the amount in the Comp_hours textbox when I put "2" in there, then click somewhere else on the page, correct? That's how onblur appears to work. I just tested the onblur by sticking document.write("Hello world"); into my function. That works, so I'm guessing it's something to do with the for loop and calling those elements to get Comp_hours_1, Comp_hours_2, etc. Now to find the issue....
|
|
|
wkempees
Posts: 1679
|
Posted: 05/13/2008, 11:54 AM |
|
Chris,
You are not looping through your grid, you merely want to multiply the users input by 1.5
as soon as the user has entered a value and tabs or in anotherway leaves the entry field?
Correct?
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
|
|
Chris__T
Posts: 339
|
Posted: 05/13/2008, 12:41 PM |
|
Yes, but in the editable grid, there can be more than one record. So let's say there are 5 records for employees. And three employee will be using some comp time. So I need (I think) to loop through them all to get to the three to do the calculation. Or maybe it doesn't need to be a in a loop, since I can only add one value to each employee at a time. I'm confused now!
If I don't need to loop, how do I get to, for example, the third employee in the list that wants to use comp time?
|
|
|
wkempees
Posts: 1679
|
Posted: 05/13/2008, 1:10 PM |
|
<td colspan="2"><label for="store_productsprice_{store_products:rowNumber}" style="display: none;">Price</label><input onblur="alert(store_productsprice_{store_products:rowNumber}.value)" id="store_productsprice_{store_products:rowNumber}" maxlength="12" size="12" value="{price}" name="{price_Name}"></td>
example code for an alert
quicky busy will give better answer later
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
|
|
wkempees
Posts: 1679
|
Posted: 05/13/2008, 2:00 PM |
|
This one works for me
<td colspan="2"><label for="store_productsprice_{store_products:rowNumber}" style="display: none;">Price</label><input onblur="store_productsprice_{store_products:rowNumber}.value = store_productsprice_{store_products:rowNumber}.value * 1.5;return true" id="store_productsprice_{store_products:rowNumber}" maxlength="12" size="12" value="{price}" name="{price_Name}"></td>
It should be a function, working on that lol.
yours should be something close to this
<td ....><label for="Employee2Comp_hoursID{Employee2:rowNumber}" style="display: none;">Price</label><input onblur="Employee2Comp_hoursID{Employee2:rowNumber}.value = Employee2Comp_hoursID{Employee2:rowNumber}.value * 1.5;return true" id=.......
Remember, I only did some work on your described job at hand.
I see some problems with it procedural not technical.
BTW: no more function comptime in the HEAD section, it is an inline function now, even the 'return true' might be extraneous (spelling?)
Walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
|
|
Chris__T
Posts: 339
|
Posted: 05/13/2008, 2:20 PM |
|
Walter. I got it. I played around with what you told me, but that didn't seem to work. I reread Nicole's tip sheet, and towards the top, she says you can also access the control by this.value
so mine looks like this:
<input onblur="javascript:this.value = this.value*1.5;" style...>
works perfectly.
Thanks Walter. I can always count on you for solutions and helping me work through issues.
|
|
|
wkempees
Posts: 1679
|
Posted: 05/13/2008, 2:23 PM |
|
your welcome always.
the this.value is good tip too!
Walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
|
|
|