www.webdeveloper.com
Results 1 to 2 of 2

Thread: Need help debugging javascript

  1. #1
    Join Date
    Mar 2005
    Posts
    65

    Need help debugging javascript

    In this javascript
    Code:
    <html>
    
    <head>
    <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>New Page 1</title>
    <script type="text/javascript">
    function New() {
    hey = document.form1.old.value;
    hey2 = hey.replace('users4.ev1.net/~java4jim','www.exploration101.com')
    alert(hey2)
    //document.form1.new.value = hey2;
    }
    </script>
    </head>
    
    <body>
    <form name="form1">
    <textarea name="old"></textarea><br>
    <input type="button" value="test" onClick="New();"><br>
    <textarea name="new"></textarea>
    </body>
    
    </html>
    I have two problems I can't seem to fix.
    1.) If I enter the word i need to change twice it only changes the first one and I need it to change all of them
    2.) I can't get the hey2 variable to go into a textarea. that's why it's commented out at the moment.

    If you know how to fix this that would help a lot!

  2. #2
    Join Date
    Sep 2003
    Location
    Utah
    Posts
    396
    Try this:

    <script type="text/javascript">
    function myFunction() {
    hey = document.form1.old.value;
    hey2 = hey.replace(/\busers4.ev1.net\/~java4jim\b/gi,"www.exploration101.com")
    document.form1.new1.value = hey2;
    alert(hey2)

    }
    </script>

    new is a reserved word, so don't use it as a name of a form field. Also, from what I read, you need to use regular expressions to replace all occurences of a substring.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles