View Full Version : onClick calling function

08-09-2005, 10:52 AM
Hi, I have a Javascript function that when called, sends values to its parent window. But for some reason the onClick command does not call the function.
Any help would be appreciated.

function SendCustomer(count)
var txtVal = document.forms["formPop"]["name"+count].value;
var txtVal1 = document.forms["formPop"]["id"+count].value;
var txtVal2 = document.forms["formPop"]["number"+count].value;
window.opener.document.forms["esg"].elements["customer_name"].value = txtVal;
window.opener.document.forms["esg"].elements["customer_id"].value = txtVal1;
window.opener.document.forms["esg"].elements["customer_number"].value = txtVal2;
<FORM NAME="formPop" action =" " method =" post">
<input type ="text" name="search" size="30"><br>
<input type =" submit" name="submit" value="search">

<input type=button Value=Select onclick=SendCustomer(1);>
<input type='text' name='name1'value='Paddy Power'readonly>
<input type ='hidden' name='id1'value='5'>
<input type=text name='number1' value='086 4545451'readonly>

08-09-2005, 11:56 AM
is the form in a popup, per chance? is the function also in the same popup?

08-09-2005, 12:03 PM
ok ... try this (notice the correct HTML):

function SendCustomer(oFld,oFrm,iCount)
var txtVal = oFrm["name"+iCount].value;
var txtVal1 = oFrm["id"+iCount].value;
var txtVal2 = oFrm["number"+iCount].value;
var oWinFrm = window.opener.document.forms["esg"];

oWinFrm.customer_name.value = txtVal;
oWinFrm.customer_id.value = txtVal1;
oWinFrm.customer_number.value = txtVal2;

<form name="formPop" method="post">
<input type="text" name="search" size="30">

<input type="submit" name="submit" value="search">
<input type="button" Value="Select" onclick="SendCustomer(this,this.form,1);">

<input type="text" name="name1" value="Paddy Power" readonly>
<input type="text" name="number1" value="086 4545451" readonly>

<input type="hidden" name="id1" value="5">

08-09-2005, 12:05 PM
Yes the form is in the pop up, and the function is on the same page as the form.

The page works by having one page with one form, and the option to bring up a pop up with another form that searches a database.
On the pop up, the user clicks on the button next to the value they wish to return to the parent window.

08-09-2005, 12:09 PM
^^ see previous post. hope that helps :thumbsup:

08-09-2005, 12:24 PM
Unfortunatly not, i have similar code working on another page, and it works no problem. Thanks for your help anyway. I'll post the code if I figure it out.

08-09-2005, 04:52 PM
Sorry for wasting everyone's time, problem was in the code I didn't add.. A day wasted.. :mad: