/    Sign up×
Community /Pin to ProfileBookmark

Function output in another function using id

I have an external JS file/function that does a calculation based on numbers entered into a form. If the output of the function equals 8 characters, then I want to control the display of it’s output so that it looks like a typewriter or decryption effect. If not, then it would just give an error message. The variable that holds the information is ‘sn’ inside of functionXYZ().

Now to the actual question….
I found a couple of cut-and-paste JS that do what I want, but can’t seem to get my results to display. In the HTML doc, they use a

[code=html]<div id=”whatever”>Text that displays with effects here.</div> [/code]

The id tells the JS what text to display. I assumed that I could just change it to read

[code=html]<div id=”whatever”><script>functionXYZ();</script></div>[/code]

but that displays “functionXYZ();” and then my results.

I should explain that I currently have the if-then-else setup as:

[CODE]if (sn.length == 8){
document.write(sn)
else {
document.write(‘ERROR’)
};
[/CODE]

Someone told me that I really shouldn’t use document.write for this situation, but didn’t give me any alternatives.

Here’s a link to the decrypting text I wanted to use: [URL=http://i-code.co.uk/javascript/decryptingtext.php]Decrypting Text[/URL]

One other smaller problem is that I would like the decrypting effect to only use random numbers and NOT random characters. I thought I could just change all the ‘char’ variables to ‘num’. Obviously, that didn’t work.

Any help is appreciated!

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@konithomimoJan 01.2007 — use the code they provide, but to use numbers instead of characters simply change the startdecrypt() function to this:

function startdecrypt(){
var d = 10000000+((99999999-10000000)*Math.random());
chars = Math.floor(d).toString();
setTimeout("change()", 10);
return true;
}


and change:

var got;

to

var got='';

That will generate a random integer(whole number) that is 8 digits long, and then call the same function as before.

You can also remove the text from the first span since it is no longer needed.

if you want the use to input a number then the code could easily be altered again to allow for input and validation.
Copy linkTweet thisAlerts:
@KorJan 01.2007 — 
Someone told me that I really shouldn't use document.write for this situation, but didn't give me any alternatives.
[/quote]

innerHTMl or DOM methods are the dynamic way to change/create/remove an element

innerHTML is the simplest, even is not standard... but is cross browser
<i>
</i>...
if (sn.length == 8){
document.getElementById('whatever').innerHTML=sn;
else {
document.getElementById('whatever').innerHTML='ERROR';
...
×

Success!

Help @bradymc spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...