<script language="javascript">
function frompost()
{
var string=$('#indexsearch').val();
var url=string.split('=');
if(url==""){
var url=string.split('video/');
}
var finalurl='http://watchvideos.tv/watch/'+url[1];
window.location = finalurl;
//$('#srchFrm').attr('action',finalurl);
//document.srchFrm.submit();
}
</script>
I have a problem with this script - it's Ok as long as indexsearch field contains = and fails when it's supposed to work as well - with video/ in the field
Bo Persson
92.9k31 gold badges153 silver badges211 bronze badges
1 Answer 1
Try it like this:
function frompost()
{
var str = $('#indexsearch').val(),
url = str.split(/=|video\//),
finalurl = 'http://watchvideos.tv/watch/'+url[1];
window.location = finalurl;
}
answered Jul 2, 2011 at 7:19
KooiInc
124k32 gold badges145 silver badges181 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
419
url[1] is passed as undefined instead of the value after video/KooiInc
What's the value of
$('#indexsearch').val()?KooiInc
Well
http://videobb.com/video/PFt6bfmNMSlW'.split(/=|video\//) returns ["http://videobb.com/", "PFt6bfmNMSlW"] here, so I'm not sure why url[1] shouldn't exist. Could video/... be in uppercase? Than use .split(/=|video\//i)lang-js