Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Problem with the User Login Windows

  1. #1
    Join Date
    Oct 2009
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem with the User Login Windows

    Gurus,

    Need I Help with this script. I want pick up the user login and put inside a hidden field.

    I tried many, many times and the script only show me a error, where is the error in my script?

    Can anyone help me?


    Code:
    <script language="JavaScript">
    	var objNet = new ActiveXObject("WScript.NetWork");
    	var strUserName = objNet.UserName;
    	var strDomain = objNet.UserDomain;	
    	var input = document.createElement("input");
    	input.setAttribute("type", "hidden");
    	input.setAttribute("name", "usuario");
    	input.setAttribute("value", strUserName);		
    	document.write(strUserName);
    	document.getElementsByTagName("form").appendChild(input);	
    </script>
    Tks

    Fabiano Magno Pechibella
    Last edited by jscheuer1; 10-03-2012 at 02:55 PM. Reason: Format

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I don't know anything about using the modifier "WScript.NetWork" when creating an active x object or if it would then contain the values you assume it does. I do know that only IE can create an active x object, all other browsers will throw an error on that. But assuming you are using IE and that using that modifier does what you expect, when you get to this line there's a syntax error:

    Code:
    document.getElementsByTagName("form").appendChild(input);
    It needs to have a bracketed index. If it's the first form on the page, then 0 would be the index:

    Code:
    document.getElementsByTagName("form")[0].appendChild(input);
    And unless this code is executed after the browser parses the form, there will still be an error because it won't find the form.

    The line:

    Code:
    document.write(strUserName);
    might overwrite the page unless at that point the browser is still parsing the page. It would be better to skip it, or to use:

    Code:
    alert(strUserName);
    There could also be other problems.

    If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Oct 2009
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi John,

    My idea is pick up the value of strUserName and put inside value in hidden field. When the user insert any information in form and save this form the value of strUserName go to DB.

    10x

  4. #4
    Join Date
    Oct 2009
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    John,

    Follow the code.

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    
    <!-- PEGA USUARIO LOGADO NO WINDOWS --> 	
    <script language="JavaScript">	
    	var objNet = new ActiveXObject("WScript.NetWork");
    	var strUserName = objNet.UserName;
    	var strDomain = objNet.UserDomain;	
    	var input = document.createElement("input");
    	input.setAttribute("type", "hidden");
    	input.setAttribute("name", "usuario");
    	input.setAttribute("value", strUserName);	
    	//coloca o elemento onde vc quer	
    	alert(strUserName);
    	//document.getElementsByTagName("hidden").appendChild(input);
    	//document.getElementsById("container").appendChild(input);
    	document.getElementsByTagName("form")[0].appendChild(input);		
    </script>
    
    <form>
    	<input type="hidden" name="usuario" value="" />
    </form>
    Last edited by keyboard; 10-04-2012 at 01:37 PM. Reason: Format: Html Tags

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Why would you want to append an input to the form that it already has? Rather than add an identical input with a new value, why not just change the value of the existing input?

    Oh, and what I said before about this only having a chance of working in IE still goes. Other browsers will throw an error. How can you know that IE will be the only browser used?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Oct 2009
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    John,

    Will I develop a intranet and the brower aproved in my job is IE. When the user access the intranet by first time i will catch the UserName login and insert in my DB. After the first access the user will win some privileges to see some areas of the intranet.

    Fabiano Magno Pechibella

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Close the browser completely. Open it and clear the cache. Hit F12 to launch developer's tools. choose the script tab. Load the page into the browser, see if anything is reported in the developer's tools. If so, copy that and post it here. If there's something you need to do with the page to cause the error, do that. If something new appears in the developer's tools, copy that and paste it here.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Oct 2009
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    John,

    Follow the print the developer's tools.


    Error

    Detalhes dos erros da página da Web

    Agente de Usuário: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)
    Carimbo de data/hora: Thu, 4 Oct 2012 18:08:23 UTC


    Mensagem: O objeto não dá suporte para a propriedade ou método
    Linha: 10
    Caractere: 2
    Código: 0
    URI: http://localhost:8500/sieb8/ActiveX.htmlClick image for larger version. 

Name:	erro-1.jpg 
Views:	142 
Size:	8.7 KB 
ID:	4786Click image for larger version. 

Name:	erro-2.jpg 
Views:	152 
Size:	12.5 KB 
ID:	4787

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    What line is line 10 of sieb8/ActiveX.html?

    If it's the code you posted, it's one of these:

    Code:
    	var objNet = new ActiveXObject("WScript.NetWork");
    	var strUserName = objNet.UserName;
    	var strDomain = objNet.UserDomain;
    Probably the first. So that means that type of active x cannot be used.

    Otherwise it means that it can but it doesn't have UserName property.

    If you click on the error in the console in developer tools, it will show you the exact line.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #10
    Join Date
    Oct 2009
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    John,

    Follow the script from developer tool tab Script

    Code:
    <script language="JavaScript">
    	var objNet = new ActiveXObject("WScript.NetWork");
    	var strUserName = objNet.UserName;
    	var strDomain = objNet.UserDomain;	
    	var input = document.createElement("input");
    	input.setAttribute("type", "hidden");
    	input.setAttribute("name", "usuario");
    	input.setAttribute("value", strUserName);		
    	document.write(strUserName);
    10 - 	document.getElementsByTagName("form").appendChild(input);	
    </script>
    Tab HTML

    Code:
    <html>
    <head>
    <title></title>
    <script language="JavaScript">var objNet = new ActiveXObject("WScript.NetWork");  var strUserName = objNet.UserName;  var strDomain = objNet.UserDomain;   var input = document.createElement("input");  input.setAttribute("type", "hidden");  input.setAttribute("name", "usuario");  input.setAttribute("value", strUserName);    document.write(strUserName);  document.getElementsByTagName("form").appendChild(input);</script>
    <body>
    G0027712
    Tks John for your help.

Similar Threads

  1. Replies: 1
    Last Post: 10-28-2010, 01:31 PM
  2. PHP User Login/Register
    By Rockonmetal in forum PHP
    Replies: 7
    Last Post: 05-17-2010, 09:13 AM
  3. mutiple user Login Script
    By jandjweb in forum JavaScript
    Replies: 1
    Last Post: 10-25-2007, 10:28 PM
  4. PhP User Login and CSS Integration
    By goringpsa in forum PHP
    Replies: 1
    Last Post: 09-20-2007, 08:09 PM
  5. MYSQL User Login
    By Rockonmetal in forum MySQL and other databases
    Replies: 3
    Last Post: 09-15-2007, 11:17 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •