Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript_howto thread: how toachieve this using javascript


Message #1 by "raji" <kmkrajalakshmi@r...> on Fri, 7 Feb 2003 07:06:07
When you set the onclick event to a function and pass a parameter 
javascript thinks you're setting the event to the result of the 
function.  You need to set the event to just the function, like this:

newrow.onclick=parent.opener.callMe;

and change callMe so it doesn't require a parameter.  Something like:

function callMe() {
	alert(this.id);
	alert("from main");
}

> i'm having two forms-main form containing a html table and a button.on 
c> licking the button it pops up a child window containing a text box and 
a 
b> utton.afer entering some text in the text box and clicking the button 
the 
c> hild window is closed and a new row with the entered text should be 
added 
i> n the main form table.I'm achieving this thru insertRow() function.i 
have 
t> o raise the onclick event for that row thru javascript and on the 
click 
e> vent i have to call a function in the main form by passing arguments 
to 
t> he function.the argument should be id of the newly created 
row.Everything 
i> s working fine but while passing the id,the event is fired for the 
first 
t> ime itself and further clicks on that row does not raise the event ? 
how 
c> an i achieve this ?

> 
T> he sample code is provided below :

> 
T> est.jsp (main form)

> <HTML> 
<> BODY> 
<> FORM method="post" name="Test" action=""> 
<> center>
<> table id="tab_test" border="1" width="100%">
<> tr>
<> td width="50%">&nbsp;</td>
<> td width="50%">&nbsp;</td>
<> /tr>
<> tr>
<> td width="50%">&nbsp;</td>
<> td width="50%">&nbsp;</td>
<> /tr>
<> /table>
<> /center>
<> /div>
<> p><input type="button" value="Button" name="B3" onclick="clickMe
()"></p>

> <script language=JavaScript>

> function clickMe() {
w> indow.open("Sample.jsp?mode = xx","AddBuilds","height = 
3> 00,width=500,top=100,left=100,alwaysRaised=yes");

> }

> function callMe(rowid) {
a> lert(rowid);
a> lert("from main");

> }

> </script> 
<> /FORM>
<> /BODY> 
<> /HTML>

> Sample.jsp

> <HTML> <BODY>
<> FORM method="post" name="Sample" action="">
<> input type="button" value="Button" name="B3" onclick="clickMe()"></p>

> <script language=JavaScript>

> 
f> unction clickMe() {
v> ar newrow; newrow=parent.opener.document.getElementById
(> "tab_test").insertRow(1);
n> ewrow.id="row1"; 
f> or (var i = 0; i < 2; i++) {
>> v_newCell = newrow.insertCell(i); 
v> _newCell.innerHTML="XX"; 
}>  
n> ewrow.onclick=parent.opener.callMe(newrow.id);//It works fine for the 
v> ery first time but fails to raise the on click event for further clicks

> window.close();

> }

> </script>

> 
<> /FORM>
<> /BODY>
<> /HTML>

> 
P> l. provide the right solution

> 
.>  
 >   
 > 
 > 
 > 
 > 
 > 

>  
 > 

  Return to Index