i have a register.php and confirmregister.php file. in the first file the user fills a registeration form and in the second page they can review what they

entered in the first page and then confirm their registration.

in register.php i am able to call a javascript file which does the validation of the form fields.

<script language="javascript" type="text/javascript" src="jscripts/erranzregistration.js">
</script>

<form id="form1" name="registrationform" method="post" action="http://website.com/php/confirmegister.php" onSubmit="return validateform()">

however in the confirmegister.php file i am using the same script tag and the same form tag but the javascript file is not being called at all.

please advice how i can call the javascript file in confirmregister.php file.

thanks.

    I would suggest using the firefox browser and then install the addons such as web developer and firebug.

    These will help identify possible javascript errors really quickly ... and even points you at potentially problem lines.

    How does your existing javascript relate to the fields that it is checking? Is it by the document.forms[0] or by using direct document.getElementById calls?

    might be worth posting a sample of the code just to allow someone to look through.

      I'm a little bit confused, in confirmregister.php you want to call the javascript. What are you trying to do? use a javascript function in your PHP? What does confirmregister.php do? PHP can't directly call javascript methods since PHP is executed on the server and JavaScript in the clients browser.

        the purpose of confirmregister.php file is to display whatever the user entered in the form in register.php so that the user can review the information they entered and if they need to make changes they can do so in confirmregister.php and finally click on register and the form will be submitted to the final php file which will insert the data into a table.

        now about my question, i am able to call a javascript file in register.php when a user clicks the submit button, i am not able to call the same javascript file in confirmregister.php because the same form is displayed again so i would like to validate again in confirmregister.php page.

        following is how i am calling the javascript file in register.php

        <script language="javascript" type="text/javascript" src="jscripts/erranzregistration.js">

        function validateform()
        {

        var username = document.registrationform.username
        if ((username.value==null) || (username.value=="") || (username.length=="") || (username.value.search(re))> -1)
        {
        alert("Please Enter a User Name")
        username.value=""
        username.focus()
        return false
        }

        return true
        }
        </script>

        <form id="form1" name="registrationform" method="post" action="http://website.com/php/confirmregister.php" onSubmit="return validateform()">

        =======================================================

        following is how i am calling the javascript file in confirmregister.php

        <script language="javascript" type="text/javascript" src="jscripts/erranzregistration.js">

        function validateform()
        {

        var username = document.registrationform.username
        if ((username.value==null) || (username.value=="") || (username.length=="") || (username.value.search(re))> -1)
        {
        alert("Please Enter a User Name")
        username.value=""
        username.focus()
        return false
        }

        return true
        }
        </script>

        <form id="form1" name="registrationform" method="post" action="http://website.com/php/confirmregister.php" onSubmit="return validateform()">

        =======================================================

        both are the same however confirmregister.php does not call the javascript file

        please advice.

          I see, now I understand.

          I see confirmregister.php is in a directory called /php/ is register.php in there too?

          I'm guessing its not in that folder and infact its in the root. i.e. they would be in a folder structure as below;

          /register.php
          /php/confirmregister.php
          /jscript/

          The problem is the path your using to the javascript is relative to the location of the PHP. so in confirmregister.php change the path to the javascriot so it has "../" at the begining.

          Then it will be;

          <script language="javascript" type="text/javascript" src="jscripts/erranzregistration.js">

          P.s. please use the BB codes in future to highlight code in posts.

            hi

            the register.php file is in the root directory, validateform.js file is also in the root directory and confirmregister.php is in a folder called php in the root directory.

            i am calling the javascript file in register.php in the following way

            <script lanaguage="javascript" type="text/javascript" src="validateform.js">

            </script>

            in confirm.php i have called the javascript file in the following ways

            1.

            <script lanaguage="javascript" type="text/javascript" src="http://website.com/php/validateform.js">

            </script>

            2.

            <script lanaguage="javascript" type="text/javascript" src="../validateform.js">

            </script>

            3.

            also i have removed the script tag and copied the entire javascript code into confirm.php file

            in both register.php and confirm.php following is the form tag

            <form id="form1" name="registrationform" method="post" action="http://website.com/php/confirm.php" onSubmit="return validateform()">

            and this validateform() function is defined in the javascript file

            none of the above 3 methods are working, i have tried these 3 options several times but they do not work.

            i am able to call the javascript file from confirm.php now, the problem is the javascript code is not being read. i used an alert statement after the validateform() function at the begining and an alert at the end of the validateform() function, only the first alert is being called and the rest of the javascript code is being ignored, even the last alert message is not being called and the confirm.php file is being called.

            what i have noticed and might be the problem is, in register.php the form fields are defined as follows

            <input type="text" name="username"> and for the rest in the same manner however in confirm.php the form fields are defined as follows

            echo "<input type =\"text\" name=\"username\" value=\"$username\">"; and so on for the others.

            since the form elements are now different from how it is defined in register.php i am thinking that this is the reason why the javascript code is being ignored as the way the form elements are defined is NOT <input type="text" name="username"> which is the convention. so i guess in confirm.php file i need to let the php file know that echo "<input type =\"text\" name=\"username\" value=\"$username\">"; is equivalent to <input type="text" name="username"> for the javascript code to work in confirm.php file.

            please advice if this is the problem or if there is any other solution and how the code should be written.

            NOTE= in confirm.php file i want to display to the user what they have entered in register.php so that they can review the information and then click on register button.

            if there is no solution i am think of making all the fields as read only in confirm.php and i should advice the users in confirm.php to click on the back button to make changes in register.php

            any help will be greatly appreciated.

            thanks.

              Write a Reply...