Jump to content
  • Advertisement
Sign in to follow this  
JavaMava

[web] having basic trouble with html forms and javascript

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

If you intended to correct an error in the post then please contact us.

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:
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'> <head> <script type='text/javascript' src='myscript.js'></script> </head> <body > <form method='post' name='signup' action='http:/school/cgi-bin/assign3.cgi' onsubmit='return(checkform())'> <input type='text' name='surname' /> </form> </body> </html>
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("<head><title>Condo Order Errors</title>     </head>");
          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;

     window.location.reload();

}





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 this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by JavaMava
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.

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

I have no problem to give you some pointers to help you on your way, but start with asking a concrete question. I see you've written some code already, what is it that is causing you problems?

Share this post


Link to post
Share on other sites
Quote:
Original post by WanMaster
Quote:
Original post by JavaMava
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.

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

I have no problem to give you some pointers to help you on your way, but start with asking a concrete question. I see you've written some code already, what is it that is causing you problems?


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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by swiftcoder
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()...


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 this post


Link to post
Share on other sites
Quote:
Original post by JavaMava
I 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 this post


Link to post
Share on other sites
Quote:
Original post by swiftcoder
Quote:
Original post by JavaMava
I 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 this post


Link to post
Share on other sites
Quote:
Original post by JavaMava
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.

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 this post


Link to post
Share on other sites
Quote:
Original post by WanMaster
Quote:
Original post by JavaMava
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.

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!