Solved

Two hidden input with the same name within different forms on the same page bugs !

Posted on 2008-06-23
6
459 Views
Last Modified: 2008-07-02
Hi experts,

I have a webpage which there is two generated forms on it where both have a field named notype.

When i try to get the value of this hidden input from javascript, I got undefined. Both forms have different names and ids.

If you want to try it, go to :
http://www.cints.net/PHP/affpage.php
Connect yourselft using the two textboxes at the top with :
Username (firstbox) : TE1
Password (secondbox) : t

From there, you can click on this link :
http://www.cints.net/PHP/affpage.php?file=searchemploye

The lastest button called "Rechercher" is the second form on the page with the Sondage form.
So, if you click on this button "Rechercher", you will get a first alert, then a second which tells you the value of the notype input.

If I remove the first form (Sondage form), then the problem is fixed. I'd like to be able to keep the same name, which I think can usually be achieve due to the existance of the function getElementsByName (Elements, the s is key). So, could someone tells me where I'm wrong.

This testing has been done with IE7.
0
Comment
Question by:djon2003
  • 4
  • 2
6 Comments
 
LVL 1

Assisted Solution

by:mudskipperw
mudskipperw earned 20 total points
ID: 21853052
give your forms with various names and use each notype is under one form which will be unique to any others. then you can have such as
alert(document.FormName1.notype.value);
alert(document.FormName2.notype.value);

more accurate than using getElementByName.
0
 
LVL 9

Author Comment

by:djon2003
ID: 21856528
The forms already have two differents names and ids : they are "sondageform" & "searchform".

The button "Rechercher" is calling this javascript function :
function searchUnite(ObjID) {
   objUnitesRequest = new Request();
   SaveUniteFromForm(ObjID,true);

   alert(curUnite.jsonData.toJSONString());
   objUnitesRequest.httpRequest("POST", "UnitesManager.php", false , uniteSearched, "page=searchunite&searchingUnite=" + encodeURIComponent(curUnite.jsonData.toJSONString()));
}

The bug is happening in the other function called SaveUniteFromForm. I'll give you only the beginning because this is something quiete big, but the problem happens at the beginning anyway.

So as you can see in the code above & below, the button calls a javascript function with his button Id as parameter. Then this param is passed to the function SaveUniteFromForm and this function create a new var called Obj which is the HTML element represented by this ID. (The button).

More, as said in the first post, If I remove the "Sondage" form (the other one) than my problem is solved. (just a reminder)
function SaveUniteFromForm(ObjID,ForSearch) {

   if (ForSearch == undefined) ForSearch = false;

    var Obj = document.getElementById(ObjID);

 

    curUnite.jsonData = new Object();

    alert(1);

    alert(Obj.form.notype.value);

    curUnite.jsonData.NoUnite = Obj.form.nounite.value;

    curUnite.jsonData.NoType = Obj.form.notype.value;

    alert(curUnite.jsonData);
 

..... not useful for the problem.

Open in new window

0
 
LVL 9

Author Comment

by:djon2003
ID: 21861356
Excuse me for this useless question, but I discovered that I faulty not correctly closed the sondage form tag.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Accepted Solution

by:
djon2003 earned 0 total points
ID: 21861370
Only 20 points because what mudskipperw gave me was already stated in the problem has done.
0
 
LVL 1

Expert Comment

by:mudskipperw
ID: 21862753
alright, 20 points then.

this msg is not an objection, but when i looked at your page and the source code, you didn't give any form any names.
in your SaveUniteFromForm, ObjID would have to be document, to be able to make the following line
    alert(Obj.form.notype.value);

still when you didn't name a form as "form", that line is going to fail the program. alternatively, you can call forms as an array
document.forms

--- "points" is not what a program is after but getting the program working. hehehe agree?

//your function...
function SaveUniteFromForm(ObjID,ForSearch) {
   if (ForSearch == undefined) ForSearch = false;
    var Obj = document.getElementById(ObjID);
 
    curUnite.jsonData = new Object();
    alert(1);
    alert(Obj.form.notype.value);
0
 
LVL 9

Author Comment

by:djon2003
ID: 21862995
Two things :
1- Up to now, I always gave all the points, but now the problem was not located there and I mostly sure that the forms were named. Anyhow, if you have the chance to answer another question I'll have in the future, for you'll certainly have all the points.

2- Obj is the button and using Obj.form is accessing the form of this button, so no name is required there. It is a special property of the inputs of a form.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now