/    Sign up×
Community /Pin to ProfileBookmark

what is wrong in this little script?

geeezzz java is tough ?

It cant find the var name.
how do i solve this?
thnx

<form name=”Getname”>
<font size=3><input name=”string” type=”text” size=15 onChange=”numtimes = 0;”></font>
<input type=”button” value=”send” onclick=myfunction()>
</form>

<script>
var name;
function myfunction(){
document.write(“<H1 align=center>Hi! “+name+”.</H1>”)
}
</script>

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliMay 20.2004 — First of all Java is completely different programming language,though JavaScript has some similarities but JavaScript is only a scripting languagge(huge diff)...?

Next it look slike you are trying to get the value in the text fiel to be dislayed?

if thats correct then here is reason why you don't see your code work properly.

var name;

menas that you are decalring a variable,but in your code you are not defining its value anywhere,so when you try to print it you will get error.

here is what you need to do.

<script>

var name;

function myfunction(){

name = document.Getname.string.value;

document.write("<H1 align=center>Hi! "+name+".</H1>")

}

</script>

the above should work.

However try not to use document.write in this manner,because it will over write your current document.
Copy linkTweet thisAlerts:
@itsmadmaxauthorMay 20.2004 — hmm.. can i store it in an ohter window?
Copy linkTweet thisAlerts:
@Khalid_AliMay 20.2004 — ????

can you be a bit more descriptive?
Copy linkTweet thisAlerts:
@itsmadmaxauthorMay 20.2004 — i tried the code you send me but its not working.

it says, document.getname.string is empty or not an object???


second:

can i say document.write(name;"anywindow.html")
Copy linkTweet thisAlerts:
@VirbatemMay 20.2004 — As Khalid Ali wrote, you have not assigned a value to the varaible 'name'.

(try not to use variable names which are also reserved words)

document.write() can only be used as the page is loading. After the page has loaded no more writing is permitted. What you have tried to do is delete the entire contents of the current document and write a new document. The variable 'name' is now gone.

Adding a new element to your page can solve your problem:

<div id=result></div>

and change your javascript from:

document.write("<H1 align=center>Hi! "+name+".</H1>")

to become:

document.getElementById("result").innerHTML=document.Getname.string.value;

http://www.iinet.net.au/~htjs/getname.htm is what you need.

Dion...

[o]

[i]Originally posted by itsmadmax [/i]

[B]geeezzz java is tough ?



It cant find the var name.

how do i solve this?

thnx



<form name="Getname">

<font size=3><input name="string" type="text" size=15 onChange="numtimes = 0;"></font>

<input type="button" value="send" onclick=myfunction()>

</form>



<script>

var name;

function myfunction(){

document.write("<H1 align=center>Hi! "+name+".</H1>")

}

</script> [/B]
[/QUOTE]
Copy linkTweet thisAlerts:
@itsmadmaxauthorMay 20.2004 — ok? that seems to work?

next question.

what I want is a kind of msg this way. Its for local use, no cgi or whatever.

is it possible that the next send will appear under or above what just appeared on the screen?

or is it 1 input and the previous can not be saved?
Copy linkTweet thisAlerts:
@VirbatemMay 20.2004 — Change the function to read:

function myFunction(theForm)

{ txt=document.getElementById("result").innerHTML;

document.getElementById("result").innerHTML=txt+"<h1>"+theForm.string.value+"</h1>";

};

We store the current contents in a variable.

Next store the variable content and the new string to the DIV layer.

http://www.iinet.net.au/~htjs/getname2.htm

Dion...

[o]


[i]Originally posted by itsmadmax [/i]

[B]ok? that seems to work?



next question.



what I want is a kind of msg this way. Its for local use, no cgi or whatever.



is it possible that the next send will appear under or above what just appeared on the screen?



or is it 1 input and the previous can not be saved? [/B]
[/QUOTE]
×

Success!

Help @itsmadmax 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.5,
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,
)...