How do I populate a form field from another window?
Here's my scenario:
Main Window:
I have a field called Zipcode
There is a link that opens a new window which enables me to search for zip codes.
ZipCode Window:
I can enter the name of a city and a list of zip codes show up.
Here's what I want:
I want to be able to click on the zip code which was found in the ZipCode Window and have that number be automatically populated in the Zipcode field which is in the Main Window
Hey great thanks! This is working good There's only one snag...I failed to state that there will be 3 zip code fields in the main window. I need to be able to fill them in independantly using this feature.
Sorry I'm not at your beck and call. I had to go to bed last night and then I had to go to work this morning. Now it's lunch time.
You would give each form field a unique id (zipcode1, zipcode2, zipcode3) and then (I'm assuming you open the window for one and make the selection, then open it for the next one, etc) you could have the id be a querystring variable passed to the popup window and use it to determine which form field gets the value
Main window, revised
Code:
<form name="zipform" action="nextpage.php" method="post">
<p><input name="zipcode1" id="zipcode1" type="text"> <a href="popup.php?fieldId=zipcode1" target="_blank">Choose from a list</a></p>
<p><input name="zipcode2" id="zipcode2" type="text"> <a href="popup.php?fieldId=zipcode2" target="_blank">Choose from a list</a></p>
<p><input name="zipcode3" id="zipcode3" type="text"> <a href="popup.php?fieldId=zipcode3" target="_blank">Choose from a list</a></p>
...
</form>
Hey, I hope I didn't come off as an ass I'm just new to this forum and didn't realize how quickly things move around here and was affraid it was going to get lost. I'm sorry for the misunderstanding
Anyways, thank you very very very much for your help! You are a code wizard
Oh and HaganeNoKokoro, you thought it was over? No!! Haha. Anyways, was wondering howi can get the zipcode finder window to open a new window at a fixed size and positioned in the center of the screen. I tried using DreamWeavers Open Window behavior, but it screws up the code and doesnt work.
Anyways, any help greatly appreciated (again)
Thanks
<script type="text/javascript">
function popup(url, x, y, w, h) {
var params="x="+x+", y="+y+", width="+width+", height="+height;
window.open(url, "_blank", params);
}
</script>
And then the links that open the windows will be like
Code:
<a href="#" onclick="popup('popup.php?fieldId=zipcode1', 100, 100, 200, 400);return false;">Choose from a list</a>
Of course you will have to change the x, y, w, and h to suit where you want the window and how big. I don't know if there's a way to make it appear in the exact center of the screen, although you could use screen.width and screen.height to calculate it.
Kids, kids... you tried your best, and you failed miserably; the lesson is: never try.
I found the ultimate way that I would like for this to work. Instead of clicking "Find This Zip" for all 3 fields, you can just click these checkboxes and do all 3 at once.
Please check out this perfect example here:
hxxp://agentmachine.com/realestate/buyhome.asp
That's EXACTLY what I want. But I don't think I can just lift the code from that site. Do you know of any similar ways of working it? Any idears?
<script type="text/javascript">
function submitForm(frm) {
var cur=1;
for(var i=0; i<frm.elements.length; i++) {
if(frm.elements[i].type=="checkbox") {
if(frm.elements[i].checked) {
window.opener.document.getElementById("zipcode"+(cur++)).value=frm.elements[i].value;
}
if(cur>4) break; //put the number of fields you want fileld here
}
}
window.close();
}
</script>
in the popup window. The form in the popup will also need a button
Bookmarks