Web Analytics Made Easy -
StatCounter Problem with onclick() event - CodingForum

Announcement

Collapse
No announcement yet.

Problem with onclick() event

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with onclick() event

    Hi all,

    I have a little javascript function that assigns the value from a parent window to a field on a iframe. The function is on the parent page and its called by a button onclick() event on the other page. It works fine the first time i click on the button but if i click again the value isn't assigned anymore.

    This is the function on the parent page:
    Code:
    <SCRIPT language=javascript>
    
    function Id(){
    	var id = frm1.PersonId.value;
    	return id;
    }
    
    </SCRIPT>
    This is how its called on the other page:

    Code:
    <BUTTON class=MsoNavAddNew id=addRecord onclick="PersonId.value=parent.Id();" MsoTextAlign="General"></BUTTON>
    I thought an onclick() event would always work when called but perhaps not

    Any ideias about this? Thanks in advance!
    Last edited by ze_colmeia; Oct 9, 2006, 07:40 AM.

  • #2
    The code you posted did not even work the first time for me.
    Your code is confusing because you are applying the return value of function Id to PersonId.value when function Id needs the value of PersonId.value to return?

    Are you passing an argument to the parent function or just retrieving from the parent?
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

    Comment


    • #3
      I'm just retrieving the value from the parent field PersonId.

      What i want to do is assign that value to the PersonId field on the "sub" page when i click the button. As i said it works fine the first time but it doesnt do anything after.

      Comment


      • #4
        Don't use id as a function name or variable as its already reserved. Also don't use the same name of your function as a variable either.
        ||||If you are getting paid to do a job, don't ask for help on it!||||

        Comment


        • #5
          I've changed the names, added a function on the second page that receives and assigns the value, called that function on the onclick event but i always get the same result.

          Wasn't supposed an onclick work everytime its called?

          Comment


          • #6
            Try this.
            When you click the button the value of str is placed in the textbox.
            Clear the textbox or type some other text in the box and press the button again, each time Hello World is entered in the box

            In the parent page

            PHP Code:
            <SCRIPT language=javascript>

            function 
            test(){
            var 
            str "Hello World"
            return str
            }

            </
            SCRIPT
            In the iframe page

            PHP Code:
            <form name="myform">
            <
            input type="text" name="PersonId" value="">
            <
            input type="button" value="Button" onclick="document.forms['myform']['PersonId'].value=parent.test()">
            </
            form
            The silent one.

            The most dangerous thing in the world is an idea.
            The most dangerous person in the world is the one with an idea.

            Comment


            • #7
              I think i know where the problem is.

              Im working with DAP's (Data Access Pages) and on this particular DAP (the iframe page) i want to have a list of all the emails related to a PersonId. The event works fine on the first line when i click the Save button but then i click on aAdd Record button to insert another row and thats when it stops working. This are buttons created by the Access Wizard.

              Perhaps this is not the indicated place for this but if anyone know a way to work this out please say it. Thanks

              Comment

              Working...
              X