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.
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.
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.
use the parseUri library here : stevenlevithan[dot]com/demo/parseuri/js/ var uri = 'www[dot]youtube[dot]com/watch?v=bnMhbbH1MMQ' var c = uri.queryKey['v'];