0

I am working on legacy app. Can someone tell me what does each line of code below return in old browsers so I can convert to the right upgraded syntax.

// form-name and input-name is just an example for a form annd input field
form-name.input-name.value 
form-name.input-name.returnValue // How is this different than the one above
form-name.input-name.setValue() //  I believe this sets the value

input is an input text field. Also the code is very IE specific. Here is an example of how an input if first selected and then those properites are called on it.

function GetInputFieldById(id) {
    return window.document.all(id)
}

var name = GetInputFieldById('name4308').returnValue;

As you can tell it is so old, they could have just used getElementById() but not sure may be it was not part of the standard spec yet. Also, the same way after input is returned setValue() is called on it.

sayayin
  • 971
  • 5
  • 23
  • 36
  • 1
    Really, they use hyphens in variable names? Can't believe that. – Bergi Oct 10 '17 at 20:50
  • `document.forms[formName].elements[inputName].value` should do it – Bergi Oct 10 '17 at 20:50
  • https://stackoverflow.com/q/6585971/1048572 and https://stackoverflow.com/q/1504346/1048572 are about how to access forms and inputs (if you cannot just use ids), but I've never heard about `returnValue` and `setValue()` – Bergi Oct 10 '17 at 20:54
  • It would help if you could post the complete actual code – Bergi Oct 10 '17 at 21:04

1 Answers1

0

I highly suggest checking out MDN. It's a fantastic JavaScript reference. Note: Both of the following features are deprecated. They are not guaranteed to work in any fashion. I've provided a modern alternative which you should switch to.


returnValue

As noted on MDN:

The Event.returnValue property indicates if the default action for this event has been prevented or not. It is set to true by default, allowing the default action to occur. Setting this property to false prevents the default action.

Basically, this means "will this action trickle up?" Events can be processed at many levels. A click on a button could also be registered as a click on a form, for example. In some older browsers, you could set returnValue to false to prevent that from happening.

In modern browsers, you would call preventDefault. For example:

input.addEventListener('click', function(e) {
  e.preventDefault();
  // do whatever...
});

Alternatively, this may relate to returnValue on an HTMLDialogElement. This is an experimental technology which, in some browsers, allows you to open dialog windows and specify what value should be returned from interacting with it. If this is the case for you, you'll most likely want to find or create a different modal system and work with the values in whatever form is correct for that implementation.


setValue(...)

I can't find any references to that function but my educated guess is that it's a non-standard way of setting the value on an element such as a text input. In modern usage this would be done with:

input.value = whateverYouWant;
Mike Cluck
  • 31,869
  • 13
  • 80
  • 91
  • 1
    Hm, the OP used `.returnValue` as a property of an input element, not an event. – Bergi Oct 10 '17 at 20:55
  • @Bergi True. I added another possible case which is a dialog element. It could be argued that a dialog is a form of input but it's difficult to say given the limited information provided by OP. – Mike Cluck Oct 10 '17 at 20:59
  • Guys, input is an input text field. Also, this code was written for old IEs. @Mike C I did do research first already have seen what you posted. But the main confusion is that the input is not a dialog nor an event. I am adding some more code to my question. – sayayin Oct 11 '17 at 18:28
  • @sayayin Then either the code is wrong or it's so old that there's no trace of the docs anywhere. At least not anywhere reasonable. – Mike Cluck Oct 11 '17 at 19:39