...

View Full Version : Using button to open page based on field value



ze_colmeia
12-06-2006, 06:09 PM
Hi all,

i have a page that with 2 text and a button. This fields are already filled with values, the first is a Person Id and the second is the Person Name. This page is dynamic so i can have multiple rows.

What i need to do is, when i click on the button at a giving line, to open a page with information about that Person. For that i need to use the Person Id field value on the onclick event but it just works for the first row... the other ones always referer to the first Id.

How can i get the Id of the row were i click the button?

nikkiH
12-06-2006, 10:48 PM
That depends.
Post code or link please.

ze_colmeia
12-07-2006, 09:58 AM
Ok. This is my onclick function


<SCRIPT language=javascript>"
function goToRecord_onclick(pId, pName){
var url=""\"PersonId=" + pId + "\" ";"
window.location.href("htmPersonalData.htm?ServerFilter=" + url);
}
</SCRIPT>


And this are my text files and button.


<SCRIPT language=javascript>"
function storeData(){
var pId=parent.ReturnId();
var pName=parent.ReturnName();

parent.document.write("<input type='text' name='PersonId' value='" + pId + "' />
<input type='text' name='PersonName' value='" + pName />
<input type='button' id='goToPerson' name='goToPerson' onclick='return goToRecord(pId, pName)' /><BR>");
}


All this code is stored on a different window. The function storeData() is called from this page parent window.

I'm still very new at javascript so any help is appreciated. Thanks.

nikkiH
12-07-2006, 02:28 PM
The language attribute is deprecated. Use type.
<script type="text/javascript">

document.write is very old school. You should be using DOM methods or at least innerHTML, depending on what browser(s) you want to support.
For this sort of thing with the form elements you should be using createElement and appendChild.

You have this line:
var pId=parent.ReturnId();

What is ReturnId?
If you want to see why pId is always the same, we have to trace it to see what the value is, and where the values are set and all that jazz. If it never changes, the button will always have the same id in that onclick.
This is what will need to really be traced into:

<input type='button' id='goToPerson' name='goToPerson' onclick='return goToRecord(pId, pName)' /><BR>");

Do you have the full page online anywhere?

ze_colmeia
12-07-2006, 04:44 PM
ReturnId() is a function located on the parent window that returns the id.

What i really want to know is how to open a page with the reference of that Id when i click on the corresponding button.

Example:
TextBox1(PersonId) | TextBox2(PersonName) | Button

I can have this several times... i want to click on the button and know the value of the TextBox1 that the button referes too...

nikkiH
12-07-2006, 10:19 PM
We're getting to the opening of a page, but first we have to make sure we actually get a new id when that function is called. It won't do us much good otherwise.
The driving force here is actually that parent function, since it is where the ID comes from.


ReturnId() is a function located on the parent window that returns the id.

The ID of what?
Is it returning the proper ID each time? Your issue is that the new page always has the same id, right? If this main function always returns the same ID, this is what is broken.

Correct me if I'm wrong, ok?
You have a window with some stuff in it, including a function called ReturnId(). This function takes no arguments, so how does it know which ID to return?

Now, that main window is opening or contains a child window. The child window is dynamically constructing textboxes whenever the function storeData() is called. storeData() also takes no arguments. Unfortunately, it looks like it is making multiple textboxes all with the same name, so now you can't tell them apart. It also makes buttons with the same ID, so now you can't tell those apart.


<input type='text' name='PersonName' value='" + pName />
<input type='button' id='goToPerson' name='goToPerson' onclick='return goToRecord(pId, pName)'

This means I really need to see the full code to help you more, because it won't work very well like that. :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum