Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multiple javascript functions are not working properly

 
Tushar Bhaware
Ranch Hand
Posts: 62
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am developing a website.Everything is working fine except my registration page. I want to apply validations on my fields.I have written functions accordingly.
They are working fine when i call one function at a time.Problem arises when i call multiple functions inside onsubmit or when i call wrapper function inside onsubmit.

Problem is that when i don't write anything inside any field, it does not focus on that element and shows alert messages of that field and other field as well and control moves to login page.
I hope you understand my problem. Please Help me.
I have put my both pages code here.

1.Login Page (which is working fine)


and here is Register page (where problem with java script)


Thanks in advance
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Wow -- that's way too much code to look through. Besides -- it's full of JSP markup which is not helpful for a JavaScript question. (And using scriptlets? Please read this JspFaq entry).

Please post an SSCCE (Short Self-Contained Correct Example) that shows the issue.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In html4, ids can not be numbers or start with a number, looks like you are using an HTML5 doc type so not a big issue. Using ints for ids is bad practice since it gives no reference to what the element is exactly, give it a meaningful name.

Another issue is you should be using a string with getElementById



Eric

 
Tushar Bhaware
Ranch Hand
Posts: 62
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Welcome to the Ranch.

Wow -- that's way too much code to look through. Besides -- it's full of JSP markup which is not helpful for a JavaScript question. (And using scriptlets? Please read this JspFaq entry).

Please post an SSCCE (Short Self-Contained Correct Example) that shows the issue.


Thank you for your reply ... I have read why not use scriptlets. I will learn JSTL and EL.Please give me some references or names of books where i can learn about JSTL and EL
And also let me know should i start a new thread with only javascript or should i write it in another comment.
Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JavaScript question should be handled here. Questions on JSP should be posted in the JSP forum.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also



b can never be null, but you are checking for it in the if.

You are calling submit onclick and onsubmit, no reason for that.

Eric
 
Tushar Bhaware
Ranch Hand
Posts: 62
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:In html4, ids can not be numbers or start with a number, looks like you are using an HTML5 doc type so not a big issue. Using ints for ids is bad practice since it gives no reference to what the element is exactly, give it a meaningful name.

Another issue is you should be using a string with getElementById



Eric



Thank you Eric,
I will remember that but thing is that it is working properly when i call a single javascript function through onsubmit and stays on the same page(register).
Problem arises when i call wrapper function which contains 4 other functions, it will show alert messages of all functions without focusing on field when it fails to comply with validation and moves to other page(login page).
 
Tushar Bhaware
Ranch Hand
Posts: 62
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:The JavaScript question should be handled here. Questions on JSP should be posted in the JSP forum.


i have problem in JavaScript,not in JSP. I thought that i would be better to give relative information about Javascript where it its operating. But anyway I will remember that from next time.
If you can give me references to JSTL and EL would be nice.
Thanks
 
Tushar Bhaware
Ranch Hand
Posts: 62
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:Also



b can never be null, but you are checking for it in the if.

You are calling submit onclick and onsubmit, no reason for that.

Eric


i will clear onclick event, will retain onsubmit.
thanks
Tushar
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you use variable names a,b,c,d and 1,2,3,4,5,6 in your Java code? It is bad practice and I would hate to be the person that has to maintain it in the future.


The reason the form is submitting is you have a JavaScript error. Open up the JavaScript console in your browser of choice and run the code. The error will appear. Depending on your debugger, you may have to persist logs across pages.

Eric
 
Tushar Bhaware
Ranch Hand
Posts: 62
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:Do you use variable names a,b,c,d and 1,2,3,4,5,6 in your Java code? It is bad practice and I would hate to be the person that has to maintain it in the future.


The reason the form is submitting is you have a JavaScript error. Open up the JavaScript console in your browser of choice and run the code. The error will appear. Depending on your debugger, you may have to persist logs across pages.

Eric


I will remember your advice , will try to give meaningful names from now on.
I will try your idea of checking my javascript in browser console. I have installed firebug.
will let you know what happens.
thanks
tushar
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you find your trying to focus on a HTML collection error?

Eric
 
Tushar Bhaware
Ranch Hand
Posts: 62
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Considering recommendation from other user, i have adjusted my code to SSCCE form.
My problem remains same. I have tried a lot in two days, changed my validation methods but problem persists.
so here it is the problem- multiple alert message shows when multiple fields remains vacant of my form. what i want is that when multiple field remains vacant,it should show alert message of first vacant field only and not others. Also there is problem with radio button validation function, when radio button is selected, form gets submitted even when other fields are vacant. This doesn't happen with other functions.
i hope you all got my problem.

here it is my code-
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


  • Ids are singular
    • You have multiple elements with the same id, that is not valid.
    • They can have the same name


  • You can not focus html collections
    • You need to select one of the radio buttons before you focus it

  • You are combining multiple function calls together wrong.
    • Either make a function and call each function
    • or combine them with &&, not a comma




Eric
 
Tushar Bhaware
Ranch Hand
Posts: 62
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply eric ... You have been great help to me.
Eric Pascarello wrote:
Ids are singular
You have multiple elements with the same id, that is not valid.
  • They can have the same name


  • Ok. I will make changes accordingly.

    Eric Pascarello wrote:
    You can not focus html collections.You need to select one of the radio buttons before you focus it
    Eric


    I didn't know that. I will correct it

    Eric Pascarello wrote:
    You are combining multiple function calls together wrong.Either make a function and call each function or combine them with &&, not a comma
    Eric


    I already tried a wrapper function but problem remains the same and when i combined them with && only validate function works which is first one to call , rest don't.
    I googled a lot but couldn't find solution.
     
    Eric Pascarello
    author
    Rancher
    Posts: 15385
    6
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    So make a function...



    Eric
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 65218
    95
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I say just stop trying to be clever and do things in the most straight-worward manner. Nothing is more irritating than code that's unclear, or doesn't work properly, because the author is trying to be clever.

     
    Tushar Bhaware
    Ranch Hand
    Posts: 62
    Chrome Eclipse IDE Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Eric Pascarello wrote:So make a function...

    Eric


    It tried it but it still didn't work. There was one problem though "missing variable name" due to comma after myFunc4 instead of semicolon.
    I also tried passing variables (vadiation1 to myFunc2 and so on)as argument to other function but it didn't work either.
    But now i have combined all functions together and made one big function,after that it is working properly which wasn't possible with my earlier validation functions.
    But with your advice,my functions improved (You can see difference with my 1st coding and last coding). Its working now.
    I hope one day i will be able to use wrapper function properly. I will put my working code after this.


    This was my first thread and you helped me immensely, i hope one day i can help someone as you helped me.
    Thank you very much for all your help.

    Tushar
     
    Tushar Bhaware
    Ranch Hand
    Posts: 62
    Chrome Eclipse IDE Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Bear Bibeault wrote:I say just stop trying to be clever and do things in the most straight-worward manner. Nothing is more irritating than code that's unclear, or doesn't work properly, because the author is trying to be clever.

    I was not trying to be clever. It's just that i am new to all these programming and i am trying to learn.
    It's just been 4 month since i have taken programming. I hope you got my point. I appreciate you taking time to comment here.

    Tushar.
     
    Tushar Bhaware
    Ranch Hand
    Posts: 62
    Chrome Eclipse IDE Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Here is a working code-
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic