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.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Sep 2010
    Posts
    122
    Thanks
    6
    Thanked 0 Times in 0 Posts

    exact first word problem

    hi i have this

    function getComboA(sel) {
    var v1 = sel.options[sel.selectedIndex].value;

    in hear i `m getting v1 as

    v1=UK00GEL GEL

    but i want to get to v1=UK00GEL



    document.getElementById('b').value =v1;

    }

    ... how do i do this to get the value only the first word

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Code:
    <script type = "text/javascript">
    var v1 = "UK00GEL GEL";
    v1 = v1.replace(/\s\w+/,"");
    alert (v1);
    </script>
    Instead of
    var v1 = sel.options[sel.selectedIndex].value;
    you can simply use
    var v1 = sel.value;

    A child of five would understand this. Send someone to fetch a child of five.
    Groucho Marx

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    Regular Coder
    Join Date
    Sep 2010
    Posts
    122
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Code:
    <script type = "text/javascript">
    var v1 = "UK00GEL GEL";
    v1 = v1.replace(/\s\w+/,"");
    alert (v1);
    </script>
    Instead of
    var v1 = sel.options[sel.selectedIndex].value;
    you can simply use
    var v1 = sel.value;

    A child of five would understand this. Send someone to fetch a child of five.
    Groucho Marx
    hi thankz for the reply ...its work for me

    another thing can i have

    var v1 = "UK00GEL GEL VERR";

    exacting the VERR word OR GEL word from this

    plzz help me for this

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by coolumanga View Post
    hi thankz for the reply ...its work for me

    another thing can i have

    var v1 = "UK00GEL GEL VERR";

    exacting the VERR word OR GEL word from this

    plzz help me for this
    Code:
    var v1 = "UK00GEL GEL VERR";
    var v2 = v1.split(" ");
    alert (v2[0] +  "   " + v2[1] +  "   " + v2[2])

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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