Go Back   Computer Forums > Web Design | Website Development > Web Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 07-29-2009, 09:17 AM   #1
Beta Member
 
Join Date: Jul 2009
Posts: 2
Red face Javascript code required

Good Afternoon.

I need help with some code please. I need to create a string of underscore characters and the string has to be the same length as another existing string or an element in an array.

So for example if I have the following......

A string 'hello world' or wordArray[0] = 'hello world'

....then I need to create a new string consisting of 11 underscore characters or however many characters are in the initial string or array element.

Hope you can help as I can't find any easy way to do this.

Thanks

BG
__________________

uplink600 is offline   Reply With Quote
Old 07-29-2009, 10:09 AM   #2
In Runtime
 
essentialx3's Avatar
 
Join Date: Jul 2009
Posts: 243
Send a message via AIM to essentialx3
Default Re: Javascript code required

you are going to need it to print an underscore for each character in the word array.
and welcome to CF
__________________

__________________
-Zack
essentialx3 is offline   Reply With Quote
Old 07-30-2009, 03:37 AM   #3
Beta Member
 
Join Date: Jul 2009
Posts: 2
Default Re: Javascript code required

Sorry but I don't understand your reply. Thank you for your welcome.

BG
uplink600 is offline   Reply With Quote
Old 07-30-2009, 11:02 AM   #4
In Runtime
 
essentialx3's Avatar
 
Join Date: Jul 2009
Posts: 243
Send a message via AIM to essentialx3
Default Re: Javascript code required

In the new string, you are going to have to add an underscore for each character in the string value
__________________
-Zack
essentialx3 is offline   Reply With Quote
Old 07-30-2009, 02:37 PM   #5
Fully Optimized
 
vampist's Avatar
 
Join Date: Oct 2008
Location: USA
Posts: 2,404
Default Re: Javascript code required

Quote:
Originally Posted by essentialx3 View Post
In the new string, you are going to have to add an underscore for each character in the string value



Here you go dude;
Code:
<script type="text/javascript">
function replace() {
	var string = document.getElementById('string').value;
	var len = string.length;
	var underscores = new Array();
	for (var i = 0; i < len; i++) {
		underscores[i]="_";
	}
	document.getElementById('spacers').innerHTML=underscores.join("");
}
</script>
<button onclick="replace()">Replace</button>
<input type="text" id="string" value="one">
<span id="spacers"></span>
__________________
Everyone's Favorite Turd xD
ET: "Phone home!"
Geek: "ping 127.0.0.1"

"If that guy knew half the $h*t that I know, his fuzzy little head would explode. " - Matthew Farrell
vampist is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 10:41 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0