Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Code that works on Fiddle but doesn't work on local

  1. #1
    Junior Member
    Join Date
    Oct 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Code that works on Fiddle but doesn't work on local

    Hi,

    I have this code: jsfiddle.net/k3b7uvhz/2/

     
    $('#addnewline').on('click', function (e) {
        e.preventDefault();
        var $textarea = $('#thetext');
        $textarea.val(function () {
            return $(this).val().substring(0, this.selectionStart) + "<br>" + $(this).val().substring(this.selectionStart);
        });
     
    });
     
    <button id="addnewline">New line</button>
    <br />
    <textarea rows="4" cols="50" id="thetext">Some text</textarea>

    My version on localhost:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Admin zone</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script type="text/javascript">
    $('#new_line').on('click', function(e){
        e.preventDefault();
        var $textarea = $('#description');
        $textarea.val(function(){
            return $(this).val().substring(0, this.selectionStart) + "<br>" + $(this).val().substring(this.selectionStart);
        });
     
    });
    </script>
    </head>
     
    <body>
    <button type="button" id="new_line">New Line - BR</button><br>
     <textarea name="description" id="description" cols="100" rows="20"></textarea>
     
    </body>
    </html>

    It works on fiddle but on local it does not work. What should be the problem?

    Cristian
    Last edited by ctincristi; October 9th, 2014 at 06:26 PM.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Code that works on Fiddle but doesn't work on local

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Sounds like gibberish.

  3. #3
    Junior Member
    Join Date
    Oct 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Code that works on Fiddle but doesn't work on local

    Done Greg, I read that topic.

  4. #4
    Junior Member
    Join Date
    Oct 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Code that works on Fiddle but doesn't work on local

    Anyone, guys?

  5. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Code that works on Fiddle but doesn't work on local

    Thread moved.

    Also posted here.

    JavaScript != Java.

Similar Threads

  1. Replies: 6
    Last Post: August 5th, 2014, 11:19 AM
  2. Program Works on NetBeans, but Jar file doesn't work correctly.
    By LeandroRodirgues in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 11th, 2013, 12:36 PM
  3. Replies: 9
    Last Post: September 15th, 2013, 02:48 PM
  4. Replies: 29
    Last Post: May 18th, 2012, 02:16 PM
  5. Program works fine but with friend it doesn't work
    By Rizza in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 1st, 2011, 01:20 PM