Click to See Complete Forum and Search --> : Fill in form fields
jrthor2
07-22-2003, 12:38 PM
I have a form where you specify an image url. I have just put in place (using asp) a button that when pushed, opens up a new window with the contents of an images folder on my server. What I would like to be able to do is, have the user click on the picture and it closed the window, and puts the url for that picture in the 'image url' text box on my form. Is this possible, and if so, how? I am not very JavsScript savvy :-)
Thanks!!
Something along these lines should help you get going...
<script type="text/javascript">
function getLoc() {
document.myform.mytext.value = document.myimage.src;
}
</script>
</head>
<body>
<a href="#" onclick="getLoc(); return false"><img src="test.gif" name="myimage"></a>
<form name="myform">
<input type="text" name="mytext">
</form>
jrthor2
07-22-2003, 12:56 PM
Would this go on the popup page?
For a popup, you are going to need something more like this:
<script type="text/javascript">
function getLoc() {
window.opener.document.myform.mytext.value = document.myimage.src;
}
</script>
jrthor2
07-22-2003, 01:05 PM
Ok, not quite following. I already have a button that launches a popup window. Where do I put thich code so that you click on the picture in the popup window, that window closes and the form field for the image URL is populated with the images url you clicked on?
sorry if this si confusing, it's getting there for me :-)
Insert this code into your popup page:
<script type="text/javascript">
function getLoc() {
window.opener.document.yourformname.yourinputname.value = document.myimage.src; //myimage is the name of the image below
}
</script>
</head>
<body>
<a href="#" onclick="getLoc(); return false"><img src="test.gif" name="myimage"></a>
jrthor2
07-22-2003, 01:13 PM
Ok, I have your code on the popup page.
Now, How do i populate the form field on the page that I hit the popup button on with the picture I choose, and then close the popup window?
Thanks for all your help.
The first part of your question should be done with the code above, and the second part can be done with window.close();
jrthor2
07-22-2003, 01:29 PM
Well, when I click on my picture, it doesn't do anything. I also tried putting window.close in the function like this:
<script type="text/javascript">
function getLoc() {
window.opener.document.yourformname.yourinputname.value = document.myimage.src; //myimage is the name of the image below
window.close();
}
</script>
But the window doesn't close either.
the link when you click the picture is this:
http://www.zluth.org/Admin/Zion_Staff/get_images.asp#
It's obviously not calling the function. Did you put this around your image? <a href="#" onclick="getLoc(); return false">
Also, don't forget to point the name of the form to your form, the name of the input area to your input area, and the image name to the name of your image.
jrthor2
07-22-2003, 01:38 PM
Ok, now, it is closing the window and populating the form fiels with "undefined"??
Did you change myimage to the name of your image?
window.opener.document.yourformname.yourinputname.value = document.myimage.src; //myimage is the name of the image below
jrthor2
07-22-2003, 01:56 PM
i just used the name "myimage" as the name for the image, is that ok?
<img src="<%= strPath & rstFiles.Fields("name").Value%>" border="0" name="myimage">
jrthor2
07-22-2003, 02:04 PM
No, that's what I have had all along
Do you have a link where I can look at it?
jrthor2
07-22-2003, 02:24 PM
Well, this is for my admin site where you have to login, but I can set up a temp username/password.
username: temp
password: login
Go to Staff and just try to add/edit one of them, but don't actually submit the form.
Thanks.
jrthor2
07-22-2003, 02:30 PM
Oops, sorry,
http://www.zluth.org/Admin
Ok... You have more than one image so it doesn't know which one to use. You'll have to give each image unique names, and then set up the link like this:
<a href="#" onclick="getLoc("imagename"); return false"><img src="test.gif" name="imagename"></a>
and the function like this:
function getLoc(img) {
window.opener.document.update_staff.image_url.value = document.eval(img).src; //myimage is the name of the image below
window.close();
}Let me know if that works for you...
jrthor2
07-22-2003, 02:52 PM
Nope, now the window doesn't even close, it just sits there and doesn't do anything.
My mistake... Try this:
<a href="#" onclick="getLoc('imagename'); return false"><img src="test.gif" name="imagename"></a>
and:
<script type="text/javascript">
function getLoc(img) {
window.opener.document.update_staff.image_url.value = document.images[img].src;
window.close();
}
</script>
jrthor2
07-23-2003, 07:14 AM
Nope, that didn't work. The window doesn't close or update my form field. You can still use the temp login to check it out.
You didn't change the function. This:
function getLoc(img) {
window.opener.document.update_staff.image_url.value = document.eval(img).src; //myimage is the name of the image below
window.close();
}
needs to be:
function getLoc(img) {
window.opener.document.update_staff.image_url.value = document.images[img].src;
window.close();
}
jrthor2
07-23-2003, 07:23 AM
Oops, you're right. It seems to be working now.
Thanks for all your help!!!
Great! You're welcome... :)