473,287 Members | 2,263 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,287 software developers and data experts.

can a function change fields without having "onchange()" in field defintion?

I am working with a system that allow me to add custom fields but I can not
add OnChange() language to the custom fields.

So I want to have a function in the header that recognizes when fieldx is
changed, do a calculation with the value of fieldx and change fieldy.

Can that be done without having to add an OnCHange() event to fieldx?

If so, can you give a quick example or link?

Many thanks.
Jul 2 '08 #1
7 2205
"TriAdmin" <lo*@invalid.comwrites:
I am working with a system that allow me to add custom fields but I can not
add OnChange() language to the custom fields.
Do you mean you can't add an onchange event at all? Note that if you
can insert any javascript code at all in the page, you can look up the
input elements and add onchange handlers at that time:

document.getElementById("some-input-element").onchange = function(e) { ... }.

though finding the elements may be more involved than that if they
don't have predicable IDs.
So I want to have a function in the header that recognizes when fieldx is
changed, do a calculation with the value of fieldx and change fieldy.

Can that be done without having to add an OnCHange() event to fieldx?
You could use setInterval to check the values of the elements, but it
may get hairy. For instance, onchange events only fire for text
inputs on blur (when the focus moves off the input element). You'd
have to emulate that behaviour yourself, and I'm not even sure you can
do that if you can't at least set onfocus and onblur events.
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Jul 2 '08 #2
"Joost Diepenmaat" <jo***@zeekat.nlwrote in message
news:87************@zeekat.nl...
"TriAdmin" <lo*@invalid.comwrites:
>I am working with a system that allow me to add custom fields but I can
not
add OnChange() language to the custom fields.

Do you mean you can't add an onchange event at all? Note that if you
can insert any javascript code at all in the page, you can look up the
input elements and add onchange handlers at that time:

document.getElementById("some-input-element").onchange = function(e) {
... }.

though finding the elements may be more involved than that if they
don't have predicable IDs.
>So I want to have a function in the header that recognizes when fieldx is
changed, do a calculation with the value of fieldx and change fieldy.

Can that be done without having to add an OnCHange() event to fieldx?

You could use setInterval to check the values of the elements, but it
may get hairy. For instance, onchange events only fire for text
inputs on blur (when the focus moves off the input element). You'd
have to emulate that behaviour yourself, and I'm not even sure you can
do that if you can't at least set onfocus and onblur events.
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Thanks. I CAN add javascript to the page but NOT in the input field. So
can I have this?
<script>
....
document.getElementById("some-input-element").onchange = function(e)
function() {
//update field_Y
}
<script>
Jul 2 '08 #3
"TriAdmin" <lo*@invalid.comwrites:
Thanks. I CAN add javascript to the page but NOT in the input field. So
can I have this?
<script>
...
document.getElementById("some-input-element").onchange = function(e)
function() {
//update field_Y
}
<script>
You'll have to make sure the assignment of the onchange property is
executed after the input element is loaded (and processed by the
browser). lots of times just putting the code at the very end of the
page will work, but to be safe, you'd probably want to use an onload
handler. Something like:

in the page body tag:

<body onload="init_my_stuff()"...

and then define init_my_stuff anywhere, as long as it's immediately
loaded:

<script>
function init_my_stuff() {
document.getElementById("some-input-element").onchange = function(e)
//update field_Y
}
</script>

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Jul 2 '08 #4
The following code is throwing an error when the page loads: Error:
document.getElementById("custom_187") is
nulldocument.getElementById("custom_187").onchange = function(e) {
alert("kjhsdkhsdkh");
}
Sorry, I am not a javascript expert - much appreciate any help!
Jul 2 '08 #5
"TriAdmin" <lo*@invalid.comwrites:
The following code is throwing an error when the page loads: Error:
document.getElementById("custom_187") is
nulldocument.getElementById("custom_187").onchange = function(e) {
alert("kjhsdkhsdkh");
}
Sorry, I am not a javascript expert - much appreciate any help!
you probably don't have an element with id "custom_187", or your code
is executing before the element is loaded and parsed. See my other
reply in this thread. If that doesn't work, it may help to post an URL
for us to check it out.
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Jul 2 '08 #6
getting it to work - pretty close now. The code does come before the fields
but should be able to take it from here - many thanks again!
Jul 2 '08 #7
SAM
TriAdmin a écrit :
The following code is throwing an error when the page loads: Error:
document.getElementById("custom_187") is
nulldocument.getElementById("custom_187").onchange = function(e) {
alert("kjhsdkhsdkh");
}
Sorry, I am not a javascript expert - much appreciate any help!

<script type="text/javascript">

function init() {
var chp = document.getElementById("custom_187");
if(!chp) alert('this field doesn\'t exist');
else
{
chp.onchange = function() {
alert('this field\'s value is : '+this.value);
}
}
}

window.onload = init;
</script>

Take care your inputs must have an id

<form blah ... >
<input name="custom_187" id="custom_187" >
<input name="custom_187_b" id="custom_187_b" >
....
</form>


variante :

<html>
<script type="text/javascript">
function updateField(field) {
field.form[field.name+'_tax'].value = field.value * 19.6 / 100;
field.form[field.name+'_total'].value = field.value * 1.196;
}
function init() {
var chp = document.getElementById("custom_187");
if(!chp) alert('this field doesn\'t exist');
else
{
chp.onchange = function() {
updateField(this);
}
}
}
window.onload = init;
</script>
<form>
amount: <input name="custom_187" id="custom_187" >
taxes: <input name="custom_187_tax" id="custom_187_tax" >
total amount: <input name="custom_187_total" id="custom_187_total" >
</form>
</html>

--
sm
Jul 2 '08 #8

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

Similar topics

2
by: Mark Durgee | last post by:
I have a "submit" button in a form that creates a record in my Filemaker database that works as it should. This is the HTML for it: <INPUT TYPE="SUBMIT" name="-New" VALUE="Add Record"> I...
1
by: Ron Brennan | last post by:
I've spent all morning on this and now think there is a (slight?) possiblity that onchange doesn't work for input type="file". Can anybody shed any light on this. The onblur fires just fine. The...
1
by: John Pastrovick | last post by:
Is there a way to load an image locally (in the client) when a selection of a file is made using input type=file. The purpose is to allow selection of a file and put the image in the browser...
5
by: Good Man | last post by:
Hi there I'm adding form fields on the fly with some javascript DOM programming. I basically just clone a hidden <div>, then adjust node properties to make this new <div> have unique values...
3
by: Norm via DotNetMonster.com | last post by:
I have an onchange event which fires when the content of an HTML textbox changes. My problem is that when I try to compare the content of this textbox with another HTML textbox using an if...
1
by: julian.tklim | last post by:
Hi, I've got an input box with popup calendar (date picker) all generated using javascipt. Once a date is selected from the datepicker window, the date value is populated back to the input...
6
by: jwarnock | last post by:
When a text field is terminated by a "tab" or change of focus, the browsers behave the same (IE, FireFox, Safari, Netscape). When the text field is terminated by a "return", then "onchange" is...
4
by: mbiasetti | last post by:
Hello, quick question (hopefully): I have a script that manipulates two "Select" elements. My onload calls a function that sets onchange for each "Select": ...
14
by: white lightning | last post by:
How to have <select onchange="this.form.submit()"and also a Submit button on one form? I have something like this: <form action="<?php $_SERVER; ?>" method="post"...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.