...

View Full Version : javascript/html alert box help



misstam
05-18-2012, 02:58 AM
hi i am having an issue with javascript on my web site.
i am a complete noob at this.

the objective is to have the page pop up an alert any time the submit button is pressed:
1st if there is no name on the form the alert says "please enter you first name" and returns a false value to the from
2nd if there is a name on the form the alert is supposed to have a thank you message

my problem is that it doesn't show the alert when there is a name

here is the code


<head>
<script type="text/javascript>
function write(person) {
alert("Thank you for conacting us, "+person+"!");
}

function formgo() {
var name=document.getElementById('namein').value;
if (name==null || name=="") {
alert("Please enter your name");
return false;
}
writety(name);
document.forms('contact').reset();
}
</script>
</head>
<body>
<form>
<fieldset id="contactinfo">
<legend>Contact Details</legend>
<label>
Name
<input type="text" name="name" id="namein" placeholder="First and Last name" />
</label>
</fieldset>
<fieldset id="submitbox">
<input type="submit" id="submit" value="Submit" onclick='formgo()' />
</fieldset>
</form>
</body>

please reply or email me (tam_gamer_acc@hotmail.com)

thank you
-misstam

Old Pedant
05-18-2012, 05:44 AM
Change <input type="submit"...<input type="button" ...[/b]

Might not be entire problem, but it's a start.

sunfighter
05-18-2012, 05:47 AM
Also
function write(person) {

SS/B

function writety(person) {

Philip M
05-18-2012, 08:48 AM
A good many problems, I am afraid.

if (name==null || name=="") {

A form field cannot be null, only "" (blank). For the so-manyth time, form validation of the pattern if (document.formname.formfield.value == "") is barely worthy of the name, and virtually useless, as even a single space, an X or a ? will return false, that is pass the validation. And of course the user can enter something silly, such as ABC123. Numeric values, such as zip codes and phone numbers, should be validated as such. Ditto email addresses. This topic has been covered many times before in this forum.

You should avoid giving names or id's to your variables/functions/arguments/forms words which are JavaScript methods/properties/attributes such as 'name' or 'id' or 'value' or 'test' or 'text' or 'checked' or 'href' or 'closed' or 'go' or 'submit' or 'replace' or 'button' or 'radio' or 'parseInt'.

document.forms('contact').reset();
should be
document.forms[0].reset();
You have no form or form element named "contact". And your form has no name nor id.

Never use the name "submit" for a submit button, because then your JS code can't call document.formname.submit() if you ever need to. But in any case your submit button should be an ordinary button. A submit button does what it says on the tin - submits a form to a server-side script.

In modern Javascript alerts should be used only for debugging - not to pass a message to the user.

You say that this is your website, but you have no way of sending the form data to the server. So the user cannot "contact us".

If you disclose your email address in a public forum you can expect to be deluged with spam.


It is your responsibility to die() if necessary….. - PHP Manual

Philip M
05-18-2012, 09:53 AM
Take no notice of iBall! ;) He only repeats what others have already contributed in order to increase his post count. His reputation has now progressed beyond "iBall can only hope to improve" to "iBall is infamous around these parts". How true. :D I think he holds the world's record for the number of times he has been banned from this forum.

There is a bird called an ostrich which thinks that if it puts its head in the sand so that it cannot see its enemies, then its enemies cannot see it!

felgall
05-18-2012, 10:41 AM
Take no notice of iBall! ;) He only repeats what others have already contributed in order to increase his post count.

I don't think I have seen a single post of his in the last month that hasn't simply echoed what was said in the prior post. Generally the suggested code is not to quite as high a standard though. Perhaps its time to start reporting such posts as contributing absolutely nothing to the thread since all they provide is a part of what the prior post provides anyway.

The more knowledgeable members of this forum don't always agree but where they disagree they limit their comments to the advantages and disadvantages of their particular viewpoint which provides those reading the post with even more information (remembering that not only the original poster will read the responses but others with similar questions who do the right thing and search the forum before posting will as well).

felgall
05-18-2012, 09:53 PM
If my posts bother you, why not put me on your Ignore List?

Because then I wouldn't be able to post corrections to your many mistakes and more people would end up believing that the antiquated solutions you provide are the right way to write their code now.

xelawho
05-18-2012, 10:26 PM
LOL

(because I actually did)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum