Remove part form input

Discussion in 'JavaScript' started by premium-theme, Mar 30, 2012.

  1. #1
    Hi all,

    I am building a site that requires users to input a url into a text field, however the output only needs one variable from the url string.
    Is there a way to make the form strip everything else using js as soon as they paste into the textfield?

    the variable is v=

    my form code is

    <input type='text' id='userInput' value='Paste your url' class="formtext" />
    <input type='image' onclick="changeText2();document.getElementById('box').style.height = '272px';"  class="formbutton" src="images/download2.png"/>
    
    Code (markup):
    i have tried loads of ideas but im kind of new to js.

    Let me know,

    Thanks.
     
    premium-theme, Mar 30, 2012 IP
  2. rainborick

    rainborick Well-Known Member

    Messages:
    424
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    120
    #2
    You need to explain the problem better. What is the "one variable"? Give an example of what the user might enter and what part of that you want to extract. Also, your <input> tag needs a 'name' attribute, or it won't be sent by browser with the form data and JavaScript won't be able to find it.
     
    rainborick, Mar 31, 2012 IP
  3. premium-theme

    premium-theme Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Basically somebody may enter a url like: http://www.youtube.com/watch?v=bnMhbbH1MMQ and all needed is bnMhbbH1MMQ
    They could also enter a url like: http://www.youtube.com/watch?v=bnMhbbH1MMQ&list=FL6Cb5W9FDFKJ1FRXVfkLuLA&index=4&feature=plcp and all needed is bnMhbbH1MMQ

    So somehow using js upon a user pasting the url into the text field it looks for v= and removes the rest.

    Dont know if its possible but would be really helpful

    Thanks.
     
    premium-theme, Apr 1, 2012 IP
  4. javamazon

    javamazon Active Member

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    66
    #4
    javamazon, Apr 20, 2012 IP