Connecting Tech Pros Worldwide Help | Site Map

onClick firing to wrong window

Member
 
Join Date: Mar 2007
Posts: 94
#1: Aug 13 '09
Hi,

I've got a link nested inside a form which, when clicked, should open a new window. Whilst it's doing this it also opens the page in the existing parent window as well.

I didn't write the code however, and it worked when not placed in a form. Is the onClick event of the form getting confused with the onclick event of the window?

Heres the header code:

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript">
  2. <!--
  3. /****************************************************
  4.      Author: Eric King
  5.      Url: http://redrival.com/eak/index.shtml
  6.      This script is free to use as long as this info is left in
  7.      Featured on Dynamic Drive script library (http://www.dynamicdrive.com)
  8. ****************************************************/
  9. var win=null;
  10. function NewWindow(mypage,myname,w,h,scroll,pos){
  11. if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*
  12.  
  13. ((screen.height-h)-75)):100;}
  14. if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
  15. else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
  16. settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no
  17.  
  18. ,toolbar=no,resizable=no';
  19. win=window.open(mypage,myname,settings);}
  20. // -->
  21. </script>
And the link code for the new window:
Expand|Select|Wrap|Line Numbers
  1. <a href="http://marlin/engeastl/scripts/RepairWorkshops/AddNew2.cfm" 
  2.  
  3. onclick="NewWindow(this.href,'UserAccess','720','340','yes','center');return false" onfocus="this.blur()" class="recordno" style="font-size: 
  4.  
  5. 1.1em;">Add a New Site</a>
And the onClick event of the form in which the link is nested:

Expand|Select|Wrap|Line Numbers
  1. <form action="Devaction_add.cfm" method="post" name="form" onKeyUp="highlight(event)" onClick="highlight(event)" 
  2.  
  3. onsubmit="return formCheck(this);">
Can anyone help?
Thanks
Neil
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Sep 5 '09

re: onClick firing to wrong window


What does highlight() do?
Member
 
Join Date: Mar 2007
Posts: 94
#3: Sep 7 '09

re: onClick firing to wrong window


It's a javascript function that highlights a field when the cursor enters it, so the user knows what bit they are filling out.
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4: Sep 8 '09

re: onClick firing to wrong window


Perhaps you want to prevent that from firing when the link is clicked.
Reply


Similar JavaScript / Ajax / DHTML bytes