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

Posts: 2
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
 
When You Register, These Ads Go Away!
Old 10-12-2006, 12:46 AM Re: I need help with some javascript:
logic ali's Avatar
Skilled Talker

Posts: 88
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, 03:17 AM Re: I need help with some javascript:
seomumbai's Avatar
Skilled Talker

Posts: 98
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

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

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


Webmaster Resources Marketplace:
Software Development Company | Webhosting.UK.com | Text Link Brokers 


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

 


Page generated in 0.13267 seconds with 12 queries