soffcec
asked on
updateParent() HTML Javascript
This code is only working if the child has only one <FORM> if more than one it won't work.
<------------------------------------------------------------------------------------->
<SCRIPT LANGUAGE="JavaScript">
function openChild(file,window) {
childWindow=open(file,window,"resizable=no,width=600,height=800");
}
</SCRIPT>
<FORM NAME="parentForm">
<INPUT NAME="pf1" TYPE="TEXT" VALUE="">
<INPUT TYPE="button" VALUE="Velja greiðanda" onClick="openChild('pop1.htm','win2')">
<------------------------------------------------------------------------------------->
<SCRIPT LANGUAGE="JavaScript">
function updateParent() {
opener.document.parentForm.pf1.value = document.childForm.cf1.value;
self.close();
return false;
}
</SCRIPT>
<FORM NAME="childForm" onSubmit="return updateParent();">
<INPUT NAME="cf1" TYPE="hidden" VALUE="TextFromChild">
<button style="float: left;">Transfer me to parent</button>
</FORM>
<br><br>
<FORM NAME="childForm" onSubmit="return updateParent();">
<INPUT NAME="cf1" TYPE="hidden" VALUE="MoreTextFromChild">
<button style="float: left;">Transfer me also to parent</button>
</FORM>
ASKER
I need to select between 2 or more answers from the child and update to Parent
I don't think a can change the name CF1 as it transfers the data to PF1 who transfers to the Parent. I would prefer to do this with <a href> and onclick but I have not found out how.
I don't think a can change the name CF1 as it transfers the data to PF1 who transfers to the Parent. I would prefer to do this with <a href> and onclick but I have not found out how.
<!----- Parent ------>
<SCRIPT LANGUAGE="JavaScript">
function openChild(file,window) {
childWindow=open(file,window,"resizable=no,width=600,height=800");
}
</SCRIPT>
<FORM NAME="parentForm">
<INPUT NAME="pf1" TYPE="TEXT" VALUE="">
<INPUT TYPE="button" VALUE="Velja greiðanda" onClick="openChild('pop1.htm','win2')">
</form>
<!------ Child ----->
<SCRIPT LANGUAGE="JavaScript">
function updateParent() {
opener.document.parentForm.pf1.value = document.childForm.cf1.value;
self.close();
return false;
}
</SCRIPT>
<FORM NAME="childForm" onSubmit="return updateParent();">
<INPUT NAME="cf1" TYPE="hidden" VALUE="TextFromChild">
<button style="float: left;">Transfer me to parent</button>
</FORM>
<br><br>
<FORM NAME="childForm" onSubmit="return updateParent();">
<INPUT NAME="cf1" TYPE="hidden" VALUE="MoreTextFromChild">
<button style="float: left;">Transfer me also to parent</button>
</FORM>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Not so good writing Javscript, where do I go from here:
<SCRIPT LANGUAGE="JavaScript">
function updateParent(form) {
//opener.document.parentForm.pf1.value = document.childForm.cf1.value;
opener.document.parentForm.pf1.value = form.getElementsByName("cf1")[0].value;
self.close();
return false;
}
</SCRIPT>
<FORM NAME="childForm" onSubmit="return updateParent(this);">
<INPUT NAME="cf1" TYPE="hidden" id="a" VALUE="TextFromChild">
<button style="float: left;">Transfer me to parent</button>
</FORM>
<br><br>
<FORM NAME="childForm1" onSubmit="return updateParent(this);">
<INPUT NAME="cf1" TYPE="hidden" id="b" VALUE="MoreTextFromChild">
<button style="float: left;">Transfer me also to parent</button>
</FORM>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
where do I go from heretest it !
ASKER
I am making a list to select customers and other information from a pop page.
I can do this by generate JavaScript with each record on the list by replacing the 'x' with unique code (0-999 a-z etc.)
But I rather want to generate the JavaScript only once.
I can do this by generate JavaScript with each record on the list by replacing the 'x' with unique code (0-999 a-z etc.)
<SCRIPT>
function uPx() {
opener.document.parentForm.pf1.value = document.childFormx.cfx.value;
self.close();
}
</SCRIPT>
<tr><td><FORM NAME="childFormx" onSubmit="return uPx();">
<INPUT NAME="cfx" TYPE="hidden" VALUE="somedata">
<button style="float: left;">Information to display</button></FORM>
But I rather want to generate the JavaScript only once.
Any reason you don't use <div> popups that remain on the same page and don't require you to open a separate browser window?
Bootstrap includes a Modal component - you can also add plugins like jQueryUI that provide the functionality.
Is there any specific reason you want to open a new browser window?
Bootstrap includes a Modal component - you can also add plugins like jQueryUI that provide the functionality.
Is there any specific reason you want to open a new browser window?
ASKER
I don´t want to load the whole list every time I open the webpage. It consist of more then 2000 records.
I don´t want to load the whole list every time I open the webpage. It consist of more then 2000 records.Ok - lets backup a bit here - I am still not understanding the use case here.
Based on your opening post you have this
<form name="parentForm">
<input name="pf1" TYPE="TEXT" VALUE="">
<input TYPE="button" VALUE="Velja greiðanda" onClick="openChild('pop1.htm','win2')">
</form>
If the button is clicked - it opens a new window with a form in it (the child).The example of the child you have given is showing two forms with identical names and identical hidden fields. There is a button that says "Transfer to parent"
What is going on here - why the multiple duplicate forms? What is the function of the forms in the popup.
Does your stack support caching?
btw, how does your stack look like?
btw, how does your stack look like?
ASKER
Yes, I understand the need for a popup - we can deal with better alternatives to a window.open later - for now I am interested to know about the two forms on the same popup with the same names - what are you trying to do there?
ASKER
I want to click on the customer name and transfer it to pop.htm and it is working fine, but I need smaller code because I repeat the Javascript with each record.
Ok I think I see where you are going with this and we can definitely make this a lot simpler for you.
Can we see your full source listing to give a context.
Can we see your full source listing to give a context.
ASKER
Now it's all there as I want it but need smaller code.
To be clear - is the child you want to simplify - you don't want to repeat the JavaScriptfor each option in the child?
<tbody><tr><td><form name="childForm1" onsubmit="return line1();">
<input name="cf1" value="1023587" type="hidden">
<button style="float: left;">1023587</button></form>
<script>
function line2() {
opener.document.parentForm1.pf2.value = document.childForm2.cf2.value;
self.close();
}
</script>
</td></tr><tr><td><form name="childForm2" onsubmit="return line2();"><input name="cf2" value="1028745" type="hidden"><button style="float: left;">1028745</button></form>
<script>
function line3() {
opener.document.parentForm1.pf2.value = document.childForm3.cf3.value;
self.close();
}
</script>
</td></tr><tr><td><form name="childForm3" onsubmit="return line3();"><input name="cf3" value="1023457" type="hidden"><button style="float: left;">1023457</button></form>
</td></tr></tbody>
ASKER
It's only the child form I want to make smaller. I don't want repeat the JavaScript for each option in the child.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Forms cannot be nested.
opener is undefined in your snippet.
Also using the same name twice is not a good idea. Use the id or the name with different, unique values to address them correctly.
Please post a concise and complete example.