0
<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
asked Jul 2, 2011 at 7:11

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

3 Comments

url[1] is passed as undefined instead of the value after video/
What's the value of $('#indexsearch').val()?
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)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.