Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 29
  1. #1
    New Coder
    Join Date
    Jun 2013
    Posts
    22
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Jquery --> JavaScript

    Hy guys First time here and i'm loving it Soo big soo many users Well i think that i will get this thing fix ... Soo I did a BHO ( Browser Help Object ) in C# to edit one website but they have taken the Jquery Lib soo just work the Javascript ... Can some one help me "translate" this to Javascript ( believe it hurts me too )

    Code:
    $('<input type=" + "text" + " id=" + "PartNumberTextBox" + ">').appendTo('body');
    $('#PartNumberTextBox').css('position','absolute');
    $('#PartNumberTextBox').css('right','6');
    $('#PartNumberTextBox').css('top','435');
    $('#PartNumberTextBox').css("+"width"+", "+"+=280"+");
    $('#PartNumberTextBox').css('background-color', '#000494');
    $('body').keyup(function(e) {
    var box1 = $('#TextboxNova');
            var box2 = $('#so_id');
            var box3 = $('#new_sn');
            var code = e.keyCode || e.which;
            if (code == '9') {
            var button = $('#book_button');
            if (event.srcElement.id === box3.attr('id'))
              box2.focus();
            else
            if (event.srcElement.id === box2.attr('id'))
    button.focus();
            else
    box1.focus();
            }
    });
    $('#TextboxNova').live("change blur keyup mouseup", function () {
    if ($('#new_part_no').val() === $('#TextboxNova').val() && $('#TextboxNova').val().length > 0){
    $('#TextboxNova').css('background-color', '#0f0');
    $("#new_sn").focus();
    }
      else
      $('#TextboxNova').css('background-color', '#f00');
      });

  • #2
    New Coder
    Join Date
    Jun 2013
    Posts
    22
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I forgot to explain that this code will be Injected on the website ( using BHO ) ...

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,777
    Thanks
    6
    Thanked 1,021 Times in 994 Posts
    Couldn’t you inject jQuery itself, too, then? Like:
    PHP Code:
    /*! jQuery v1.10.1 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license
    //@ sourceMappingURL=jquery-1.10.1.min.map
    */
    (function(e,t){var n,r,i=typeof t,o=e.location,a=e.document,s=a.documentElement,l=e.jQuery,u=e.$,c={},p=[],f="1.10.1"})(window);
    // jQuery library code shortened for demonstration

    $('<input type=" + "text" + " id=" + "PartNumberTextBox" + ">').appendTo('body');
    $(
    '#PartNumberTextBox').css('position','absolute');
    $(
    '#PartNumberTextBox').css('right','6');
    $(
    '#PartNumberTextBox').css('top','435');
    $(
    '#PartNumberTextBox').css("+"width"+""+"+=280"+");
    $(
    '#PartNumberTextBox').css('background-color''#000494');
    $(
    'body').keyup(function(e) {
    var 
    box1 = $('#TextboxNova');
            var 
    box2 = $('#so_id');
            var 
    box3 = $('#new_sn');
            var 
    code e.keyCode || e.which;
            if (
    code == '9') {
            var 
    button = $('#book_button');
            if (
    event.srcElement.id === box3.attr('id'))
              
    box2.focus();
            else
            if (
    event.srcElement.id === box2.attr('id'))
    button.focus();
            else
    box1.focus();
            }
    });
    $(
    '#TextboxNova').live("change blur keyup mouseup", function () {
    if ($(
    '#new_part_no').val() === $('#TextboxNova').val() && $('#TextboxNova').val().length 0){
    $(
    '#TextboxNova').css('background-color''#0f0');
    $(
    "#new_sn").focus();
    }
      else
      $(
    '#TextboxNova').css('background-color''#f00');
      }); 
    in one file.

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Jquery is JavaScript - you just need the JQuery library to define the functions (which it does using JavaScript).
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,536
    Thanks
    80
    Thanked 4,490 Times in 4,454 Posts
    I will take a stab at it.

    But no guarantees, at all.
    Code:
    (
       function() 
       {
           var inp = document.createElement('input');
           inp.id = 'PartNumberTextBox';
           inp.style.position = 'absolute';
           inp.style.right = '6px';
           inp.style.top   = '435px';
           inp.style.width = '280px'; // ?? guessing ?? original was WEIRD coding
           inp.style.backgroundColor = '#000494';
           document.body.appendChild( inp );
    
           var nova  = document.getElementById('TextboxNova'); 
           var so    = document.getElementById('so_id');
           var newsn = document.getElementById('new_sn');
           var button = document.getElementById('book_button');
           var newpart = document.getElementById('new_part_no');
           document.body.onkeyup = function(e) 
           {
               if ( e == null ) e = window.event;
               var code = e.keyCode || e.which;
               if (code == '9') 
               {
                   if ( e.srcElement == newsn )
                   {
                       so.focus();
                   } else if ( e.srcElement == so ) {
                       button.focus( );
                   } else {
                       nova.focus();
                   }
               }
           }
        
           nova.onchange  = novafunc;
           nova.onblur    = novafunc;
           nova.onkeyup   = novafunc;
           nova.onmouseup = novafunc;
           function novafunc( )
           {
               if ( newpart.value === nova.value && nova.value.length > 0 )
               {            
                   nova.style.backgroundColor = '#0f0';
                   newsn.focus();
               } else {
                   nova.style.backgroundColor = '#f00';
               }
           }
    
       }
    )();
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    Lucas Azevedo (06-20-2013)

  • #6
    New Coder
    Join Date
    Jun 2013
    Posts
    22
    Thanks
    4
    Thanked 0 Times in 0 Posts
    First of all THANK YOU FOR ALL THAT ALL YOU GUYS MADE FOR ME


    Quote Originally Posted by Old Pedant View Post
    I will take a stab at it.

    But no guarantees, at all.
    Code:
    (
       function() 
       {
           var inp = document.createElement('input');
           inp.id = 'PartNumberTextBox';
           inp.style.position = 'absolute';
           inp.style.right = '6px';
           inp.style.top   = '435px';
           inp.style.width = '280px'; // ?? guessing ?? original was WEIRD coding
           inp.style.backgroundColor = '#000494';
           document.body.appendChild( inp );
    
           var nova  = document.getElementById('TextboxNova'); 
           var so    = document.getElementById('so_id');
           var newsn = document.getElementById('new_sn');
           var button = document.getElementById('book_button');
           var newpart = document.getElementById('new_part_no');
           document.body.onkeyup = function(e) 
           {
               if ( e == null ) e = window.event;
               var code = e.keyCode || e.which;
               if (code == '9') 
               {
                   if ( e.srcElement == newsn )
                   {
                       so.focus();
                   } else if ( e.srcElement == so ) {
                       button.focus( );
                   } else {
                       nova.focus();
                   }
               }
           }
        
           nova.onchange  = novafunc;
           nova.onblur    = novafunc;
           nova.onkeyup   = novafunc;
           nova.onmouseup = novafunc;
           function novafunc( )
           {
               if ( newpart.value === nova.value && nova.value.length > 0 )
               {            
                   nova.style.backgroundColor = '#0f0';
                   newsn.focus();
               } else {
                   nova.style.backgroundColor = '#f00';
               }
           }
    
       }
    )();
    Thanks Old Pedant for this GIANT help ... i don't know too mutch about javascript but isn't there syntax errors ? i made some adventures and try to fix your code ... can you please see the diferences and if it's all okay ?

    Code:
    (
    
    function () {
        var inp = document.createElement('input');
        inp.id = 'PartNumberTextBox';
        inp.style.position = 'absolute';
        inp.style.right = '6px';
        inp.style.top = '100px';
        inp.style.width = '280px';
        inp.style.backgroundColor = '#000494';
        document.body.appendChild(inp);
        var nova = document.getElementById('PartNumberTextBox');
        var so = document.getElementById('so_id');
        var newsn = document.getElementById('new_sn');
        var button = document.getElementById('book_button');
        var newpart = document.getElementById('new_part_no');
        document.body.onkeyup = function (e) {
            if (e === null) e = window.event;
            var code = e.keyCode || e.which;
            if (code == '9') {
                if (e.srcElement == newsn) {
                    so.focus();
                } else if (e.srcElement == so) {
                    button.focus();
                } else {
                    nova.focus();
                }
            }
        };
    
        nova.onchange = novafunc;
        nova.onblur = novafunc;
        nova.onkeyup = novafunc;
        nova.onmouseup = novafunc;
    
        function novafunc() {
            if (newpart.value === nova.value && nova.value.length > 0) {
                nova.style.backgroundColor = '#0f0';
                newsn.focus();
            } else {
                nova.style.backgroundColor = '#f00';
            }
        }
    
    })();

  • #7
    New Coder
    Join Date
    Jun 2013
    Posts
    22
    Thanks
    4
    Thanked 0 Times in 0 Posts
    JSHint Report

    /*jshint forin:true, noarg:true, noempty:true, eqeqeq:true, bitwise:true, strict:true, undef:true, unused:true, curly:true, browser:true, indent:4, maxerr:50 */

    Errors:

    Line 4: var inp = document.createElement('input');

    Missing "use strict" statement.

    Line 18: if (e === null) e = window.event;

    Expected '{' and instead saw 'e'.

    Line 20: if (code == '9') {

    Expected '===' and instead saw '=='.

    Line 21: if (e.srcElement == newsn) {

    Expected '===' and instead saw '=='.

    Line 23: } else if (e.srcElement == so) {

    Expected '===' and instead saw '=='.

    Feel like some warnings are incorrect? You can configure JSHint to turn off some warnings. Read more in the documentation.
    Jshint it's giving me this errors ...

  • #8
    New Coder
    Join Date
    Jun 2013
    Posts
    22
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Sorry double post guys but i don't know why is this happening ..

    ok let's go :

    Code:
    function () {  
    "use strict";
        var inp = document.createElement('input');
        inp.id = 'PartNumberTextBox';
        inp.style.position = 'absolute';
        inp.style.right = '6px';
        inp.style.top = '435px';
        inp.style.width = '280px';
        inp.style.backgroundColor = '#000494';
        document.body.appendChild(inp);
        var nova = document.getElementById('PartNumberTextBox');
        var so = document.getElementById('so_id');
        var newsn = document.getElementById('new_sn');
        var button = document.getElementById('book_button');
        var newpart = document.getElementById('new_part_no');
        document.body.onkeyup = function (e) {
          if (e === null) {
            e = window.event;
            var code = e.keyCode || e.which;
            if (code === '9') {
                if (e.srcElement === newsn) {
                    so.focus();
                } else if (e.srcElement === so) {
                    button.focus();
                } else {
                    nova.focus();
                }
            }
          }
        };
    
        nova.onchange = novafunc;
        nova.onblur = novafunc;
        nova.onkeyup = novafunc;
        nova.onmouseup = novafunc;
    
        function novafunc() {
            if (newpart.value === nova.value && nova.value.length > 0) {
                nova.style.backgroundColor = '#0f0';
                newsn.focus();
            } else {
                nova.style.backgroundColor = '#f00';
            }
        }
    
    })();
    With this code there is no error in Jshint but this is what's happening :



    Why is out of the frame ? The textbox isn't appearing on the website

  • #9
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,777
    Thanks
    6
    Thanked 1,021 Times in 994 Posts
    Quote Originally Posted by Lucas Azevedo View Post

    Why is out of the frame ?
    Because you tell it to be: document.body.appendChild(inp);
    You need to append it to the desired frame, not to the frameset. Also, an ID must be unique in a document, you can’t have multiple elements with the same ID.
    Quote Originally Posted by Lucas Azevedo View Post

    The textbox isn't appearing on the website
    Most likely because a frameset element can’t have anything else but frame elements as children.
    Using a frameset is a bad idea anyway.

  • #10
    New Coder
    Join Date
    Jun 2013
    Posts
    22
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by VIPStephan View Post
    Because you tell it to be: document.body.appendChild(inp);
    You need to append it to the desired frame, not to the frameset. Also, an ID must be unique in a document, you can’t have multiple elements with the same ID.


    Most likely because a frameset element can’t have anything else but frame elements as children.
    Using a frameset is a bad idea anyway.
    Soo it would be like this ?

    document.frmMain.appendChild(inp);

  • #11
    New Coder
    Join Date
    Jun 2013
    Posts
    22
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by VIPStephan View Post
    Because you tell it to be: document.body.appendChild(inp);
    You need to append it to the desired frame, not to the frameset. Also, an ID must be unique in a document, you can’t have multiple elements with the same ID.
    The problem is that i'm just doing one time ... he adds 3 ...


    Quote Originally Posted by VIPStephan View Post
    Most likely because a frameset element can’t have anything else but frame elements as children.
    Using a frameset is a bad idea anyway.
    frames.childName.window.eval.call(frames.child_name.window, myCode);

  • #12
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,536
    Thanks
    80
    Thanked 4,490 Times in 4,454 Posts
    Quote Originally Posted by Lucas Azevedo View Post
    Jshint it's giving me this errors ...
    None of those "errors" are important.

    You could fix all of them, but they won't change how the code works.

    I have no idea why you get multiple <input>s added when you only invoke the code one time.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #13
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,983
    Thanks
    56
    Thanked 557 Times in 554 Posts
    Here's a question that may not lead to anything... how do you invoke that code?

  • #14
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,536
    Thanks
    80
    Thanked 4,490 Times in 4,454 Posts
    He showed that:
    Code:
    frames.childName.window.eval.call(frames.child_name.window, myCode);
    which is pretty ugly, but might actually work.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #15
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Why use the latest JavaScript with "use strict" and HTML that was superceded back in 1997 wen HTML 4 replaced <frame> with <object>
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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