Web Analytics Made Easy -
StatCounter Passing a piece of text......... - CodingForum

Announcement

Collapse
No announcement yet.

Passing a piece of text.........

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Passing a piece of text.........

    I would like to only pass a piece of data from a text box.....

    If a user enters a machine name WXXX0999 (all workstation have the same naming convention) I want to only pul the XXX0 part of that name.

    Any ideas....


    Thanks

  • #2
    what do you want to do with the text you pull, i don't quite understand.

    You pull the XXX0 part from the textbox that has WXXX0999

    then what happens to the XXX0 part.

    To create a function that will probably find and remove that text(part) i need to know how to place it within the function


    CYWebmaster.com - See why we dot com!!
    ACJavascripts.com - Cut & Paste Javascripts!
    SimplyProgram.com - Personal Blog

    Comment


    • #3
      It will eventually need to be submitted to SQL


      Thanks

      Comment


      • #4
        That cannot be done with javascrpit you will need to use a server-side script, i suggest useing cgi.

        Yes in javascrpit you can find a piece of text and do things with it like replace it, or change it ect. but to submit it to SQL that can only be done useing server-side languages.

        If i'm wrong please someone let me know.
        CYWebmaster.com - See why we dot com!!
        ACJavascripts.com - Cut & Paste Javascripts!
        SimplyProgram.com - Personal Blog

        Comment


        • #5
          If they are all pretty much the same style of machine name, why
          ask the user to enter the lot?

          Please complete your machine name<br>
          W <input type="text" name="machnam" width="40" maxlength="4"></input> 999
          ضkii - formerly pootergeist
          teckis - take your time and it'll save you time.

          Comment


          • #6
            function fnTest(){
            var longMachine = new Array;
            longMachine[0] = fname.mname.value;
            var shortMachine = "";
            for(i=1; i<5; i++){
            shortMachine += longMachine[0].charAt(i);
            }
            window.alert(shortMachine);
            }

            <form name=fname>
            <input name=mname type=text value="wxxx0999">
            <input type=button onclick="fnTest()" value=Test>
            </form>

            Maybe this is going about it the long way, but I use the array.Split method with this to validate input boxes. Since you don't need the .Split, you could just use this. I tested it for you and the xxx0 will end up in variable shortMachine. (I didn't check for empty strings, so you might want to add that.) Hope this helps.

            -Amy
            Some days you are the bug; some days you are the windshield.

            Comment


            • #7
              function getShort(str) {
              return str.match(/W(.{4})999/i)[1];
              }


              getShort('WXXX0999') == 'XXX0'; //true
              jasonkarldavis.com

              Comment


              • #8
                I would go with the regular expression jkd posted.

                Regular Expression = elegant (and sexy code).
                Former ASP Forum Moderator - I'm back!

                If you can teach yourself how to learn, you can learn anything. ;)

                Comment


                • #9
                  WXXX0999 (all workstation have the same naming convention)
                  pulling the XXX0 part...

                  You're getting it from a textbox, so go ahead and stick it in a variable, say myString. For retrieving the XXX0 part, use :

                  var XXX0 = myString.substring(1,5);

                  This will return the value of XXX0 from WXXX0999. This way you can avoid those intimidating regular expressions!
                  If at first you don't succeed, spend more time online researching javascript!
                  Beck

                  Comment


                  • #10
                    Okay, so maybe I need to spend a little more time than a couple of months learning Javascript, Perl, and all this web programming before trying to help out. Hey it may be long but it worked!

                    -Amy
                    Some days you are the bug; some days you are the windshield.

                    Comment


                    • #11
                      Thanks.... I can use all the help I can get.... It's good for me to see different ways to do things....

                      Comment


                      • #12
                        There's nothing wrong with your solution either, Amy!
                        Former ASP Forum Moderator - I'm back!

                        If you can teach yourself how to learn, you can learn anything. ;)

                        Comment

                        Working...
                        X