[web] having basic trouble with html forms and javascript

This topic is 3666 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

It's for an assignment. Part one was to make form for ordering condos, which I've done. Part two is to write some javascript that will validate whats been entered. I've looked over the examples, but just can't get it working. I know it's a lot to ask, but could one of you give me a quick working example of html code that allows you to enter some text (including the form parameters to load in the js file) as well as a js file that displays the text in a new window? Not using alert. There's a ton more to the assignment to that, but I think that's simple enough and with a working example of that I could do the rest. Heres a basic idea, couldn't find a html tag
Quote:

and the js something like
function validateName()
{
name = document.signup.surname.value;
num = [[[[[[0]]]]]];

// check if empty
if (name.length == [[[[[[0]]]]]])
{
num++;
errorString = errorString.concat("<li>Name must be entered</li>");
}

return num;
}

function checkform()
{

errors = [[0]];
errors += validateName();

if (errors > [0]){
newwin = open("","Error Messages","");
newwin.document.write("<html>");
newwin.document.write("<body>");
newwin.document.write("<ul>");
newwin.document.write(errorString);
newwin.document.write("</body></html>");

}
if (errors == [0])
return true;
else
return false;

}


I realize that code is most likely errorful I was just using it as an example of what I'd like. Thank you very much for your time. EDIT - made some chagnes to the js [Edited by - JavaMava on December 1, 2008 12:42:03 PM]

Share on other sites
Quote:
 Original post by JavaMavaI know it's a lot to ask, but could one of you give me a quick working example of html code that allows you to enter some text (including the form parameters to load in the js file) as well as a js file that displays the text in a new window? Not using alert.

No, it's your assignment, not ours. And please use the source tags when you include code.

Share on other sites
Quote:
Original post by WanMaster
Quote:
 Original post by JavaMavaI know it's a lot to ask, but could one of you give me a quick working example of html code that allows you to enter some text (including the form parameters to load in the js file) as well as a js file that displays the text in a new window? Not using alert.

No, it's your assignment, not ours. And please use the source tags when you include code.

I realize it's my assignment. I'm not asking you to do my assignment. I'm asking for as simple of an example as I thought possible to show me where I'm going wrong in this. I've included code of what I needed, so as to show I'm not trying to get you guys to do it for me, just show me a working example of what I have.

They're are literally dozens of input fields in my form that need a variety of validation checks. All I'm asking is for a start to get the form and java script "talking" to each other.

I realize your hostility is based around people coming here asking "can you write a calculator program for me" or "I need a free programmer for a game idea I have", but I'm not one of them.

Anyways, there are now source tags so you guys can read it easier. As for a concrete question. When the user click on the submit button I want the js to start the validation. The example up there being if errors > 0 then I need it to open a new window and display what the errors are. Also if false I'd like it to not submit the info and allow the user to try again on the form.

I'll greatly appreciate any help I receive.

Share on other sites
Your html code look as if it does exactly what you describe, so any problems you are having are probably in the javascript. I notice immediately that your checkForm() function doesn't every call validateName()...

Share on other sites
Quote:
 Original post by swiftcoderYour html code look as if it does exactly what you describe, so any problems you are having are probably in the javascript. I notice immediately that your checkForm() function doesn't every call validateName()...

whoops, lol.

That was a copy pasta error from my code. My actual document I'm working on is a few hundred lines longer.

errors += validateName();

is the line I've added. If an error is found in validateName, it returns a value higher than 0. That value is then added on to errors.

I have it open a new tab (might be a firefox thing), but not a window. Even more importantly there's no content in this new tab, where I am expecting everything from the document.write statements. It's stuck in a continual load or something.

Finally my form submits the info even though a false should be returned.

Thanks a lot for your help, but I'm a bit away from my goal still.

Share on other sites
Quote:
 Original post by JavaMavaI have it open a new tab (might be a firefox thing), but not a window.
That is a firefox thing, it always opens new tabs, rather than windows - should open a new window under IE or Safari.

Quote:
 Thanks a lot for your help, but I'm a bit away from my goal still.
Documentation is always a good thing to have, in particular try here.

Share on other sites
Quote:
Original post by swiftcoder
Quote:
 Original post by JavaMavaI have it open a new tab (might be a firefox thing), but not a window.
That is a firefox thing, it always opens new tabs, rather than windows - should open a new window under IE or Safari.

Quote:
 Thanks a lot for your help, but I'm a bit away from my goal still.
Documentation is always a good thing to have, in particular try here.

Thanks a ton I got it to work. Now I can go on with the rest of my assignment.

THANKS!

Share on other sites
Quote:
 Original post by JavaMavaI realize your hostility is based around people coming here asking "can you write a calculator program for me" or "I need a free programmer for a game idea I have", but I'm not one of them.

I apologize if my reaction came across as hostile, which was certainly not my intention. I guess in hindsight you did ask somewhat of a concrete question (opening a new window), but because it was convoluted by the unreadable code sample it read as a "here's my code why doesn't it work" kind of post.

But you've got it working, that's all that matters.

Share on other sites
Quote:
Original post by WanMaster
Quote:
 Original post by JavaMavaI realize your hostility is based around people coming here asking "can you write a calculator program for me" or "I need a free programmer for a game idea I have", but I'm not one of them.

I apologize if my reaction came across as hostile, which was certainly not my intention. I guess in hindsight you did ask somewhat of a concrete question (opening a new window), but because it was convoluted by the unreadable code sample it read as a "here's my code why doesn't it work" kind of post.

But you've got it working, that's all that matters.

I accept your apology. In the future I'll try and ask more concrete questions and I'll use source tags so you guys can read it easily. In the end I'll be the one who benefits from it.

Thanks.

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
12

• 12
• 16
• 26
• 10
• 44
• Forum Statistics

• Total Topics
633767
• Total Posts
3013738
×