Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Oct 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using button to open page based on field value

    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?

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    That depends.
    Post code or link please.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New Coder
    Join Date
    Oct 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok. This is my onclick function
    Code:
    <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.
    Code:
    <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.

  • #4
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    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?

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #5
    New Coder
    Join Date
    Oct 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...

  • #6
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    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.
    Code:
    <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.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •