/    Sign up×
Community /Pin to ProfileBookmark

javascript+firefox

I have a page that has a link that opens a popup window that displays a list of images. When the user clicks the image they want, it closes the window, and populates a form text field with the url to that image. The script only works in IE, but I’d like to get t working in firefox. Can anyone help?

[code]
<script type=”text/javascript”>
function getLoc(img) {
window.opener.document.<%=form_name%>.product_image.value = document.images(img).src;
window.close();
}
</script>
[/code]

The link on the popup page calls the getLoc function:

[code]
<a href=”#” onclick=”getLoc(‘<%=img%>’); return false”>image</a>
[/code]

Thanks

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@violent_jJan 22.2007 — you'd better use the getElementById() method.

so give the input box 'product_image' an id and use this piece of script:

window.opener.document.getElementById('product_image').value = document.images(img).src;
Copy linkTweet thisAlerts:
@jrthor2authorJan 22.2007 — that didn't work, it didn't close the window, or update that form input box on my form page.
Copy linkTweet thisAlerts:
@JPnycJan 22.2007 — Admittedly I don't know exactly what you're trying to do here, but be aware you cannot close a window with scripting that you didn't open with scripting.
Copy linkTweet thisAlerts:
@jrthor2authorJan 22.2007 — Ok, here is what i have.

Page 1 has a button that opens a popup window:
<i>
</i>&lt;script language="JavaScript" type="text/javascript"&gt;
function opendbwin(){
popupWin = window.open('get_images.asp?from=add','','width=760,height=600,top=120,left=80,scrollbars=yes,resizable=yes,status=no');
}
&lt;/script&gt;
&lt;input name="browse_images" type="button" id="browse_images" value="Browse images" onclick="opendbwin();" class="button"/&gt;

On the popup window, I have the script that I want to update Page 1's form's input box with the url for the image
<i>
</i>&lt;script type="text/javascript"&gt;
function getLoc(img) {
window.opener.document.getElementById('product_image').value = document.images(img).src;
window.close();
}
&lt;/script&gt;
&lt;a href="#" onclick="getLoc('&lt;%=img%&gt;'); return false"&gt;&lt;img src="test.png" border="0" name="test.png"&gt;&lt;/a&gt;
×

Success!

Help @jrthor2 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 6.18,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...