419
419

Reputation: 179

javascript split

<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

Upvotes: 0

Views: 147

Answers (1)

KooiInc
KooiInc

Reputation: 122906

Try it like this:

function frompost()
{
  var str = $('#indexsearch').val(),
      url = str.split(/=|video\//),
      finalurl = 'http://watchvideos.tv/watch/'+url[1];
  window.location = finalurl;
}

Upvotes: 1

Related Questions