tags:

views:

329

answers:

1

What my code trying to do is to add new group if it is not yet created,well, that's work fine now however I also want to open a new popup window as soon as the group is created, prompting user to invite other, but I don't seems to get my work working, any idea on how to make it works?

thanks

<html>
<head>
<script type="text/javascript">

function addGroup()
{
  x=document.getElementById("group").getElementsByTagName("p");
  groups=document.getElementById("groupName");
  var j=0,i=0;  


  if   (groups.value=="")
  {
      alert('must create one group');
  }



   for (i=0;i<x.length;i++)
   { 
     if (x[i].innerHTML == groups.value)
     {
         alert('the group name is already created');
         return false;
     }  
   }



   if (!j)
   {
      var newNode=document.createElement('p');
      var newString=document.createTextNode(groups.value); 
      newNode.appendChild(newString);
      x[0].parentNode.appendChild(newNode);
      newWindow();
   }
}

function newWindow()
{
    window.open('http://invite Others.html','invite  
                         others','width=400,height=200,toolbar=yes,                             
      location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,
                             resizable=yes');
      winObj.focus();
}
</script>

</head>
<body>

<div id="group">
<ul>
   <p>Group03</p>
   <p>Group02</p>
</ul>
</div>

<p><input type="text" id="groupName" size="84" maxlength="84" value=""/></p>
<p><input type="button" value="create" onclick="addGroup()" /></p>
<p><input type="button" value="remove" onclick="removeNo()"/> </p>
</body>
</html>
+1  A: 

Your issue seems to be window.open(). http://invite others.html is not a valid webaddress thus it returns an error.

Firebug returned this when I click create.

uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMJSWindow.open]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://localhost/ :: newWindow :: line 43" data: no]

However if you use http://localhost/invite Others.html it works fine. So just add your hostname after the htttp:// and you should be good to go.

Ballsacian1
what do you mean with hostname? is it just by inserting the word "localhost". I tried it but it does not seem to work. the invite others.html is in the same directory with this file. Couldn't I just use "invite others.html", but why it does not work? sory new to javascript
if you did window.open('newfile.html') that would work. Either remove the HTTP portion of the file path, or use your DNS name Ex: http://www.google.com/myfile.js
Ballsacian1