Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
I need help with some javascript:
Old 10-06-2006, 01:17 PM I need help with some javascript:
Junior Talker

Posts: 2
Trades: 0
I am trying to replace [[x y z]]
with
<a href="http://en.wikipedia.org/wiki/x_y_z">x y z</a>".
, similarly i am trying to replace [[x#y]]
with
<a href="http://en.wikipedia.org/wiki/x#y">x#y</a>
-----
here is what I have so far:
<html>
<head>
<title>Project.Link</title>
</head>
<body>
<script type= "text/javascript">
var input = window.prompt("Enter Text Here");
for(i=0;i<=input.length;i++)
{
var openbrackets = input.indexOf("[[");
var closebrackets = input.indexOf("]]");
var linkstart = openbrackets+2;
var linkend = closebrackets--;
var link = input.substring(linkstart, linkend);
}
for (i=linkstart;i<=linkend;i++)
{
if (link.charAt(i) == " ")
{
var replace_ = link.replace(" ", "_");
}
}
for (i=0;i<=input.length;i++)
{
var replaceo = input.replace("[[", '<a href="http://en.wikipedia.org/wiki/'+replace_+'">');
var replacec = input.replace("]]", '</a>');
}
var sentence = replaceo.concat(link);
var tsentence= document.write(sentence.concat(replacec));
</script>
</body>
</html>

------

Can anyone help me? Where is my code wrong?!?!
thenextbesthang is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-11-2006, 11:46 PM Re: I need help with some javascript:
logic ali's Avatar
Super Talker

Posts: 104
Trades: 0
Quote:
Originally Posted by thenextbesthang View Post
I am trying to replace [[x y z]]
with
<a href="http://en.wikipedia.org/wiki/x_y_z">x y z</a>".
, similarly i am trying to replace [[x#y]]
with
<a href="http://en.wikipedia.org/wiki/x#y">x#y</a>

Where is my code wrong?!?!
Life's to short to care. I don't know what characters and spacing you accept, but try this using alphanumeric characters:
Code:
do
{
 var userInput = window.prompt("Enter [[x y z]] or [[x#y]]");

 if(userInput)
 {
  userInput=userInput.replace(/\[\[\s*(\w)\s+(\w)\s+(\w)\s*\]\]/, "<a href=\"http://en.wikipedia.org/wiki/$1_$2_$3\">$1 $2 $3</a>");
 
  userInput=userInput.replace(/\[\[\s*(\w)#(\w)\s*\]\]/, "<a href=\"http://en.wikipedia.org/wiki/$1#$2\">$1#$2</a>");

  alert(userInput);
 } 

}while(userInput);
logic ali is offline
Reply With Quote
View Public Profile
 
Old 10-16-2006, 02:17 AM Re: I need help with some javascript:
seomumbai's Avatar
Skilled Talker

Posts: 98
Trades: 0
I think tht sending special characters is not accepted. so u try by using a alphabet which would be good.
seomumbai is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to I need help with some javascript:
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.26917 seconds with 12 queries