Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Help? Why won't simple script work?
Old 09-05-2008, 08:27 PM Help? Why won't simple script work?
Skilled Talker

Posts: 68
Name: Avi Zolty
Location: Atlanta
Trades: 0
Okay, so i'm learning Js and dont know why this scrip doesn't work?
<html>
<head>
</head>
<body>
<script type="text/javascript">
prompt("whats ur name","name")
if
{
name== Josh
}
document.write("hey bro");
else
document.write("go away");
</script>
</body>
</html>
Zoltar1992 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-05-2008, 09:17 PM Re: Help? Why won't simple script work?
Defies a Status

Posts: 2,071
Name: carl
Location: UK
Trades: 0
I'm learning to and am no expert but you seemed to have positioned the {} wrong and the syntax is a little out. Try this, I think it should work.

Code:
 
<script type="text/javascript">
name=prompt("Please tell me your name.","Enter you name here");
if (name == "josh")
{
document.write("hey bro");
}
else 
{
document.write("go away");
}
</script>
From what little I understand your better using an HTML form <input> rather than the promt though.

Just added this for the form as mentioned above, hope it helps.

Code:
 
<script type="text/JavaScript">
function hey (form) {
    var name = form.box.value;
    if (name == "josh")
{
document.write("hey bro");
}
else 
{
document.write("go away");
}
 }
</script>
 
<form name="myform" action="" method="get">
<input type="text" name="box" value="" />
<input type="button" name="button" Value="Please enter your name and click here" onClick="hey(this.form)" />
</form>
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Last edited by bakerc; 09-06-2008 at 05:34 AM..
bakerc is offline
Reply With Quote
View Public Profile Visit bakerc's homepage!
 
Old 09-09-2008, 02:51 AM Re: Help? Why won't simple script work?
Average Talker

Posts: 25
Trades: 0
var name=prompt("whats ur name","name");
if(name=="Josh")
document.write("hey bro");
else
document.write("go away");



1.declare the variable "name"
2.Josh is a String.
3.grammar should be if(){}else{}
softhink is offline
Reply With Quote
View Public Profile
 
Old 09-09-2008, 07:47 AM Re: Help? Why won't simple script work?
Defies a Status

Posts: 2,071
Name: carl
Location: UK
Trades: 0
Isn't that exactly what I posted above without the syntax? which you need for it to work
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Last edited by bakerc; 09-09-2008 at 07:48 AM..
bakerc is offline
Reply With Quote
View Public Profile Visit bakerc's homepage!
 
Old 09-09-2008, 12:19 PM Re: Help? Why won't simple script work?
Skilled Talker

Posts: 68
Name: Avi Zolty
Location: Atlanta
Trades: 0
Yeah, thanks ALOT baker
Zoltar1992 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Help? Why won't simple script work?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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





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



Page generated in 0.18225 seconds with 12 queries