Somejerk
Somejerk

Reputation: 193

Standard JavaScript for this

I'm working on some 15 year old code and there is a line that only seems to actually get set and be usuable in IE. I can't change that line because there actually more of them and referenced in other asp pages, I know, a nightmare. The code:

parent.frmParent.id_item.value = '<%=Request("id_item")%>' //The actual string
                                                           //doesn't matter...

I've tried:

var parent.document.getElementById("id_item").Value
var parent.document.getElementById("frmParent")("id_item").Value

Am I close? It must exist in the DOM.

Upvotes: 0

Views: 75

Answers (5)

hugomg
hugomg

Reputation: 69934

Ah, I see it now. Your problem here probably is that IE will automatically add things that are ids in the document as properties of the corresponding window object. In those cases you will want to replace the property access with a document.getElementById(idName).

By looking at your example, my psychic powers say that frmParent is a normal Javascript property (pointing to another javascript window) band id_item is an element ID (of something in the grandparent document). If this is the case, see if the following works:

parent.frmParent.document.getElementById("id_item").value = /*...*/

Upvotes: 0

qJake
qJake

Reputation: 17129

Your post is tagged javascript, but this snippet is definitely server-side: <%=Request("id_item")%>.

This will simply print out the id_item field from the Request collection (or possibly call a method named Request). You should look into what server-side frameworks are running behind this page and update your post accordingly. Without more knowledge of what language you're using, I can't help more.

Upvotes: 0

jbabey
jbabey

Reputation: 46647

I'm going to go on a long shot here:

<%=Request("id_item")%> could be referring to the querystring value for the key id_item of the .NET Request object. try using this instead:

var qs = window.location.search(1);
var items = qs.split('&');
var pair;
var result;

for (var i = 0; i < items.length; i++) {
    pair = items[i].split('=');

    if (pair[0] === 'id_item') { // the QS key
        result = pair[1]; // the QS value
        break;
    }
}

var element = document.getElementById(result);

It might be worth putting the querystring logic into a function e.g. getQuerystringValue(querystring, key).

On a side note, the property is .value, not .Value, javascript is case sensitive.

Upvotes: 0

freefaller
freefaller

Reputation: 19953

It should be the lower case value (instead of Value)...

parent.document.getElementById("id_item").value

Upvotes: 1

Alnitak
Alnitak

Reputation: 339806

Am I close? It must exist in the DOM.

I suspect you're looking for .value - i.e. just in lower case, e.g.

var val = parent.document.getElementById("id_item").value;

which would be the way to retrieve the value from an element with id id_item.

However I suspect that's not what the code is supposed to be doing...

Upvotes: 0

Related Questions