?
Solved

track hidden fields value.

Posted on 2006-05-09
10
Medium Priority
?
864 Views
Last Modified: 2008-01-09
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
Comment
Question by:nifmcm
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 3

Expert Comment

by:vincent_figo
ID: 16638595
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
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 16638597
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
 
LVL 3

Author Comment

by:nifmcm
ID: 16638691
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Expert Comment

by:Richard Quadling
ID: 16638713
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
 
LVL 3

Expert Comment

by:vincent_figo
ID: 16638787
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
 
LVL 17

Assisted Solution

by:Cem Türk
Cem Türk earned 1000 total points
ID: 16638794
<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
 
LVL 3

Author Comment

by:nifmcm
ID: 16638806
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
 
LVL 40

Assisted Solution

by:Richard Quadling
Richard Quadling earned 1000 total points
ID: 16638858
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
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 1000 total points
ID: 16638936
<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
 
LVL 3

Author Comment

by:nifmcm
ID: 16639033
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question