Urgent Javascript Help

This is a discussion on "Urgent Javascript Help" within the JavaScript Forum section. This forum, and the thread "Urgent Javascript Help are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Sep 18th, 2006, 01:04
New Member
Join Date: Sep 2006
Location: Sydney
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Urgent Javascript Help

Hi All

I have a problem with Javascript, I need to do something fairly complicated and I'm not sure how.
first let me explain what I am trying to do.
I need a user to be able to enter a single word in a text form on a page. i then need to seperate every character in that string to create new variables (example: var charater1 = string.charAt(0)) there are ten characters in total.
I then need to compare the character to find the appropriate integer number for it, for example A would equal the integer number 1.
once I have converted all ten characters I then need to write them to a file, something like a text file or the like.

does anyone know how to do this? really need help
Reply With Quote

  #2 (permalink)  
Old Sep 18th, 2006, 03:29
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Urgent Javascript Help

Writing to a text file is possible, but it makes use of ActiveX. Hence, only Internet Explorer users will be able to do it. Unless I am misinformed, Firefox and Safari won't work.

PHP is a language that you can do what you want in.

In case this is what you meant: There is no way to write a file to a users computer. Only files on your server that you have permission to read and write can be edited.
Reply With Quote
  #3 (permalink)  
Old Sep 18th, 2006, 03:32
New Member
Join Date: Sep 2006
Location: Sydney
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Urgent Javascript Help

i am using a web server so I can in theory read and write to a text file contained on the web server. Unfortunatley I am confined to Javascript to do this (it's one of the limitations to our software). using an ActiveX shouldn't be a problem, I just can't get my head around the code to do what i need to be done.
Reply With Quote
  #4 (permalink)  
Old Sep 18th, 2006, 04:15
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Urgent Javascript Help

I'm afraid I'm not much help in that field. Do some Google searches to try and locate a nice tutorial on it. Other than a simple Ajax function, I haven't delved into ActiveX objects because I've been working on a Mac for 4 years.
Reply With Quote
  #5 (permalink)  
Old Sep 18th, 2006, 07:01
New Member
Join Date: Sep 2006
Location: Sydney
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Urgent Javascript Help

Thanks ryanfait, it is a tricky thing that I'm trying to do and would be easier if I wasn't limited to using Javascript.
I figured that if I use something like a two dimension array i could get half way there but the problem there is how to I split the characters of the string and then search through the array to find the corresponding letter and then display the second column of that array and store it into a new variable.
it's bloddy difficult.
Reply With Quote
  #6 (permalink)  
Old Sep 18th, 2006, 12:09
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: Urgent Javascript Help

Set up a string of the allowable characters in the order you want them enumerated, eg;

var allow = 'ABCDE...';
var inpstr = document.getElementById('inputID');
var output;
for (i=0; i < inpstr.length; i++){
output = output + (allow.indexOf(inpstr.charAt(i)) + 1) + ':';
}
<!-- The + 1 above allows for strings being indexed from 0. The ':' is used as a seperator. Up to you if you need something like this -->

Can't tell you how to use ActiveX to right the output variable to a local file.
Reply With Quote
  #7 (permalink)  
Old Sep 18th, 2006, 23:13
New Member
Join Date: Sep 2006
Location: Sydney
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Urgent Javascript Help

I have tried to implement that code, using a function from a form in the body of the page but it doesn't work. I think I might have done it wrong? the code is:

<script language="JavaScript">
var allow = " ABCDEFGHIJKLMNOPQRSTUVWXYZ,./*[];:1234567890";
var inpstr = document.getElementById("test");
var output=0
function runscript(form){
for (i=0; i < inpstr.length; i++){
output = output + (allow.indexOf(inpstr.charAt(i)) + 1) + ':';
}
}
<!-- The + 1 above allows for strings being indexed from 0. The ':' is used as a seperator. Up to you if you need something like this -->
function display(){
document.write(output)
document.write(inpstr)
}
</script>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form>
<input id="test" type="text" onKeyUp="runscript(this.form)">

</form>
<table border="1"><Tr><td><script>display()</script></td></Tr></table>
</body>
Reply With Quote
  #8 (permalink)  
Old Sep 19th, 2006, 09:08
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: Urgent Javascript Help

For starters, the only time your display() function gets called is when the page first loads. It needs to be called once your runscript() function finishes.

At the moment, your runscript() function is called after each character is entered. Is this your intention? Originally you refered to the user entering a single word, so I had assumed they would enter the completed word before the function was run. Otherwise you don't need the for loop.

Also, the way you have the code, the var 'inpstr' is set when the page is loaded, not when the input text is evaluated.

Code: Select all
 <script language="JavaScript">
var allow = " ABCDEFGHIJKLMNOPQRSTUVWXYZ,./*[];:1234567890";
var output='';
 function runscript(){
var inpstr = document.getElementById("test");
 for (i=0; i < inpstr.length; i++){
output = output + (allow.indexOf(inpstr.charAt(i)) + 1) + ':';
}
display();
}
<!-- The + 1 above allows for strings being indexed from 0. The ':' is used as a seperator. Up to you if you need something like this -->
function display(){
document.write(output)
document.write(inpstr)
}
</script>
The bits in bold have either been changed, added or moved. For the purposes of testing, I've added a submit button which as you can see from the code will trigger the 'runscript()' function.
Code: Select all
 <form onsubmit='runscript();'>
 <input id="test" type="text">
<input type=button' value='Submit'>
</form>
Get rid of the 'display()' function from inside your table element.

Now see how you get on.

Last edited by ukgeoff; Sep 19th, 2006 at 09:11.
Reply With Quote
  #9 (permalink)  
Old Sep 20th, 2006, 00:41
New Member
Join Date: Sep 2006
Location: Sydney
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Urgent Javascript Help

Thanks ukgeoff, I tried the mods to that script but when I try and run it, It doesn't work.
I can't see why so I put an alert instead of trying to write it to a table but the alert box just came up blank.
any suggestions?
Reply With Quote
  #10 (permalink)  
Old Sep 20th, 2006, 10:29
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,620
Blog Entries: 1
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
Re: Urgent Javascript Help

You just had to search...
http://www.irt.org/script/279.htm


The charCodeAt function gives you the ASCII code for any given character...
The easiest way would be to do this:
Code: Select all
<script>
function Scramble(f){
 var output = '';
 var s = f.elements['string'].value;
 for(var i=0;i<=s.length; i++){
  output += ''+s.charCodeAt(i);
 }
 f.elements['output'].value = output;
}
</script>
<form onsubmit="Scramble(this); return false;">
 <input type="text" name="string"/>
 <input type="submit" value="GO"/>
 <br/>
 Output: <input type="text" name="output"/>
</form>
But to write a file you will need some sort of server-side language or use Java instead of Javascript...
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)

Last edited by spinal007; Sep 20th, 2006 at 10:33.
Reply With Quote
  #11 (permalink)  
Old Sep 20th, 2006, 11:11
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: Urgent Javascript Help

Let me see the actual code you now have.
Reply With Quote
  #12 (permalink)  
Old Sep 20th, 2006, 11:20
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: Urgent Javascript Help

Spinal:
If you read the initial post, the person wants 'A' to be 1 and so on, so the use of the charCodeAt function is not relevant. It will just confuse the issue for them.
Reply With Quote
  #13 (permalink)  
Old Sep 21st, 2006, 06:54
New Member
Join Date: Sep 2006
Location: Sydney
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Urgent Javascript Help

Hi Geoff

the code I am using is :

<script language="JavaScript">
var allow = "ABCDEFGHIJKLMNOPQRSTUVWXYZ,./*[];:1234567890";
var output='';
var inpstr='';
function runscript(){
var inpstr = document.getElementById("test");
for (i=0; i < inpstr.length; i++){
output = output + (allow.indexOf(inpstr.charAt(i)) + 1) + ':';
}
display();
}
<!-- The + 1 above allows for strings being indexed from 0. The ':' is used as a seperator. Up to you if you need something like this -->
function display(){
alert(output)
}
</script>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form>
<input id="test" type="text">
<input name="Submit" type='button' value='Submit' onClick="runscript()">
</form>
<table border="1"><Tr><td>&nbsp;</td></Tr></table>
</body>
</html>

I added the var inpstr=''; because when I ran it the first time it said that inpstr was not defined.
thanks again for your help
Adam

Reply With Quote
  #14 (permalink)  
Old Sep 21st, 2006, 08:53
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: Urgent Javascript Help

Where is the top part of this file?

Code: Select all
 <table border="1"><Tr><td>&nbsp;</td></Tr></table>
Not likely to be the cause of your problem but the highlighted bits above should be al lowercase.
Reply With Quote
  #15 (permalink)  
Old Sep 21st, 2006, 11:15
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,620
Blog Entries: 1
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
Re: Urgent Javascript Help

Right, I don't mean to confuse anyone BUT...
"a".charCodeAt(0) returns 97
"a".charCodeAt(0)-96 returns 1
that's the encryption problem solved...

charCodeAt is the quickest way to retrieve the character code AND can also be used for validation:
if(char.charCodeAt(0)>=65 && char.charCodeAt(0)<=122){
// do the thing
}
there's no need for long string constants OR regular expressions.

then all you need is to build a decent interface, which you guys seems to be doing.



This might be usefull:
www.lookuptables.com - ASCII Table
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Reply With Quote
  #16 (permalink)  
Old Sep 21st, 2006, 12:39
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: Urgent Javascript Help

Yes I take your point but it assumes that the allowable characters are going to be contiguous in the ascii table and there was no indication that this was going to be the case.

The version I gave him allows the user to set-up whatever sequence of characters they want.
Reply With Quote
  #17 (permalink)  
Old Sep 21st, 2006, 13:26
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,620
Blog Entries: 1
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
Re: Urgent Javascript Help

fair enough...
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Reply With Quote
  #18 (permalink)  
Old Sep 21st, 2006, 22:47
New Member
Join Date: Sep 2006
Location: Sydney
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Urgent Javascript Help

Hi Geoff

I just checked that but no change i still get an empty alert box.

Adam
Reply With Quote
  #19 (permalink)  
Old Sep 21st, 2006, 22:52
New Member
Join Date: Sep 2006
Location: Sydney
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Urgent Javascript Help

Hi geoff

I have fixed that but it didn';t change the resul;, I still get an empty alert box,

Adam
Reply With Quote
  #20 (permalink)  
Old Sep 22nd, 2006, 09:13
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: Urgent Javascript Help

I'd like to see the complete file.

There should be some code above what you have shown us so far.
Reply With Quote
Reply

Tags
urgent, javascript, help

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need some urgent help....!!!! shevorne Web Page Design 9 Sep 30th, 2007 23:36
JavaScript Menu - HELP Plz , URGENT prismmb JavaScript Forum 1 Oct 13th, 2006 17:49
Urgent Javascript help (2 script coincide error) bmass JavaScript Forum 0 Jul 21st, 2006 05:56
Urgent help in Javascript calendar display cloudymegz JavaScript Forum 3 Jan 8th, 2006 14:37
urgent help req.. s_mazhar Graphics and 3D 5 Oct 31st, 2005 09:04


All times are GMT. The time now is 01:09.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43