• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 868
  • Last Modified:

track hidden fields value.

hi there,

i'd like to be able to do something similar to the onchange event, but with an input type="hidden". i basically want to track if the value of the hidden field has changed... if so, fire an event.
does anyone have any suggestions on the best way to go about doing this?

thanks,
nikki
0
nifmcm
Asked:
nifmcm
  • 4
  • 3
  • 2
  • +1
3 Solutions
 
vincent_figoCommented:
The change of the value of a hidden field can only be triggered by another event or function... So every time this event or function is run, you know the value has changed. You can always check if old value = new value, to make sure the value has actually changed. But i would just keep track of changes in the same function as where you change the value of the hidden field.
0
 
Richard QuadlingSenior Software DeveloperCommented:
Hi nifmcm,

The only way the hidden value COULD be changed would be in code. If you don't write the code then you don't need to test to see if it has changed.

Unless I'm missing something.



Regards,

Richard Quadling.
0
 
nifmcmAuthor Commented:
yeah, i am trying to avoid affecting the origional code... it is a bought product and making changes to it means that if we get an update, we'll have to ensure we make the same changes... and with time and change of developers, it could turn into a nasty problem later on. also, the product is used in a multitude of places and the hidden field tracking is only needed in 1 of those places.

i was thinking of using a setTimeOut function to check the value, but was wondering if anyone had a better way of doing it?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Richard QuadlingSenior Software DeveloperCommented:
What I mean is WHAT can change the hidden field? The user cannot change it.

Which means some code is changing it.

It is there that you need to deal with it.
0
 
vincent_figoCommented:
A hidden field doesn't has any events that could do such a thing. The best way to do it, is to add code at the place where the code that changes the value is located. I understand your dillemma, but that is the problem with bought products, they are never flexible enough and are hard to adjust to your needs... So you will have to make a choise...

1) Either leave it like it is now
2) Change the code in the product
3) Use an extremely inefficient and difficult method to create a workaround for the problem
4) Create your own program instead of a bought product...
0
 
Cem TürkSenior Software EngineerCommented:
<HTML>
<HEAD>
<script type="text/javascript">
var initVal="val1";
function chkVal() {
if(document.getElementById("inval").value!=initVal) {
alert("value is changed");
document.getElementById("inval").value=initVal;
}
}
window.setInterval("chkVal()",1000);
</script>

</HEAD>
<BODY>

<form>
<input type="hidden" name="inval" id="inval" value="val1">
<input type="button" onclick="this.form.inval.value='blabla';" value="Change The Value">


</BODY>
</HTML>
0
 
nifmcmAuthor Commented:
the code in the product changes the hidden field.
as i said, i don't want to change that code... it is to be used in a number of places which do not need this functionality, plus, if we get an upgrade at some point, we'd have to reapply any changes to that version.

i am trying to write something external to the methods that change the value of the hidden field. i simply want to watch and see when that field does get changed.
0
 
Richard QuadlingSenior Software DeveloperCommented:
RIght I see. A timeout would work.

There is an onpropertychange event for INPUT type="hidden".

Maybe you can attach some code to this event.

e.g.

<script language="JavaScript">
input_hidden_id.onpropertychange = HiddenChanger;

function HiddenChanger()
 {
 alert('I was changed.');
 }
</script>

maybe. (UNTESTED).
0
 
Richard QuadlingSenior Software DeveloperCommented:
<html>
<head>
<title>Test onpropertychange</title>
</head>
<body>
<form>
<input type="hidden" name="foo" id="foo" value="bar">
</form>
<button onClick="alert(document.getElementById('foo').value);document.getElementById('foo').value = 'boo';alert(document.getElementById('foo').value);">Press me</button>
<script language="JavaScript">
document.getElementById('foo').onpropertychange = HiddenChanger;

function HiddenChanger()
 {
 if (event.propertyName != 'onpropertychange')
       {
      alert('The ' + event.propertyName + ' was changed.');
      }
 }
</script>
</body>
</html>

This works fine in IE, but not in FF.

Hmmm...

http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21609861.html
0
 
nifmcmAuthor Commented:
unfortunately, mine has to work in Firefox too. but, if it didn't, the onpropertychange event would be just the thing!
happily, i am using the setInterval option and it works well in both.

thanks for all the input! (the pun is intended... sad, i know!)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now