/    Sign up×
Community /Pin to ProfileBookmark

Can’t set form value in parent window?

I have an odd problem, and I really can’t see where I’m going wrong with this. I have a page with a form on it called “entryform”. This form has a hidden field called “imagefile” and a button beside it called “Choose Image”. There is also an <img> tag called “showimage” which displays the currently selected image.

The “Choose Image” button opens a new window with a list of images. Each image has a SELECT link beside it. The code for the SELECT link looks like this:

[code]<a href=”#” onClick=”window.opener.document.showimage.src=’images/ninestein.jpg’;window.opener.document.entryform.imagefile.value=’1′;”>SELECT</a><br>[/code]

On clicking the select link, the src attribute of “showimage” is correctly changed to the chosen image (in this case images/ninestein.jpg), and the picture changes back in the original window. However, the value in the hidden “imagefile” input tag doesn’t change. This is supposed to change to reflect the database number of the selected image (in this case, ‘1’).

I can verify this by changing “imagefile” from a hidden to a text field. The of “imagefile” never changes. I’m at my wit’s end, I can’t figure out what’s wrong with my code. I’m a bit of a JS newbie, but this seems simple enough. Any thoughts, anyone?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisMay 29.2007 — &lt;a href="#" onClick="window.opener.document.showimage.src='images/ninestein.jpg';window.opener.document.entryform.imagefile.value='1';[color=red]return false[/color]"&gt;SELECT&lt;/a&gt;&lt;br&gt;
×

Success!

Help @DiscoBurgess spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...