www.webdeveloper.com
Results 1 to 6 of 6

Thread: simple, yet complex for newbie

Hybrid View

  1. #1
    Join Date
    Aug 2009
    Posts
    4

    simple, yet complex for newbie

    Hi, I new to the whole javascript and webdesign game. So here is my question:

    From the parent window I want to open a child window and then from the same function to change a value on a form in the child window. Here is what I have for code:

    Code:
    <script language="javascript">
    
    function opencourse(url,name,details)
    {
            
        newwindow = window.open(url,name,'height=420,width=605');
        try {    
            newwindow.document.title = name;
            newwindow.document.getElementByID('hideme').value = details;
            }
        catch(e) {
            newwindow.onload=function(){newwindow.document.title.value = name;
            newwindow.document.getElementByID('hideme').value = details;
    }
        newwindow.focus();
    }
    
    </script>
    and then the link that calls the function looks like this:
    HTML Code:
    <a href="javascript:opencourse('http://www.imisd.com/Forms/course.php','intake','Procurement and Contract Negotiations Skills')">

    Then in the child window the form calls itself and uses the php mail() function to send the info to a specified email address. Here is the form code:

    HTML Code:
    <form method="POST" action="course.php" name="intakeform" id="intakeform">
    
    <fieldset class="fltright"><legend>Position Details</legend>
    <label for="Title">Title:</label><br />
    <input type="text" name="Title" id="Title" class="textfield"><br />
    <label for="Department">Department:</label><br />
    <input type="text" name="Department" id="Department" class="textfield"><br />
    <label for="Company">Company:</label><br />
    <input type="text" name="Company" id="Company" class="textfield"><br />
    <label for="Website">Website:</label><br />
    <input type="text" name="Website" id="Website" class="textfield"></p>
    <label for="Comments">Comments/Questions:</label><br />
    <textarea name="Comments" id="Comments" class="textarea"></textarea><br />
    <p>Fields marked (*) are required</p>
    
    </fieldset>
    
    <fieldset >
    <legend>Personal Information</legend>
    <label for="Salutation">Salutation:</label><br />
    <input type="text" name="Salutation" id="Salutation" class="textfield"><br />
    <label for="Name">Name:* </label><br />
    <input type="text" name="Name" id="Name" class="textfield"><br />
    <label for="Address">Address:</label><br />
    <textarea name="Address" id="Address" class="textarea"></textarea><br />
    <label for="eMail">eMail:* </label><br />
    <input type="text" name="eMail" id="eMail" class="textfield"><br />
    <label for="Tel">Tel:</label><br />
    <input type="text" name="Tel" id="Tel" class="textfield"><br />
    <label for="Fax">Fax:</label><br />
    <input type="text" name="Fax" id="Fax" class="textfield"><br />
    <label for="Mobile">Mobile:</label><br />
    <input type="text" name="Mobile" id="Mobile"  class="textfield"></fieldset>
    
    
    
    <input type="hidden" name="hideme" id="hideme" /> 
    
    
    
    <input type="submit" id="submit" class="submit" >
    </form>
    I use to have a simpler function that tried to open window and directly change the values, but then once it was finished loading it would change everything back to its original value.

    Any ideas what does this and how to solve this problem which has had me pulling at my hair the whole day?

  2. #2
    Join Date
    Jun 2009
    Location
    Miami
    Posts
    118
    Instead of using script to set values in form controls during HTML parsing of the child window or even after it is loaded (parsed), why not use script to write the HTML markup as script strings, allowing you to set the form control values directly?

    For example:

    Code:
        var chldWin = open(...);
       chldWin.document.write("<form action=\"something\">");
       chldWin.document.write("<input value=\"" + valueFromParent + "\">);
       chldWin.document.write("<\/form>");
       chldWin.document.close();
    Note that your values are set as defaults in the input element through the attribute.

  3. #3
    Join Date
    Aug 2009
    Posts
    4
    So if I'm getting you right, I should write the whole form through script?

  4. #4
    Join Date
    Aug 2009
    Posts
    4
    Does that mean that I have to write the php code, styling and other html code through the script as well, or is there a way where I can simply write between the <body></body> tag ??

  5. #5
    Join Date
    Jun 2009
    Location
    Miami
    Posts
    118
    Quote Originally Posted by ZenAnthro View Post
    So if I'm getting you right, I should write the whole form through script?
    When creating a child window through script, the HTML and everything else basically written in using document.write() methods for HTML (you have to use DOM methods for XHTML, since document.write() is undefined). Doesn't have to be literal strings. Any text you can take in from inline or external JS files, or even references to displayed/visible or undisplayed/invisible content of DOM nodes.


    Quote Originally Posted by ZenAnthro View Post
    Does that mean that I have to write the php code, styling and other html code through the script as well, or is there a way where I can simply write between the <body></body> tag ??
    Your first document is an (X)HTML that contains a button or I suppose an anchor as you have it, that opens the child window with the form to be completed, and perhaps some controls (text boxes) filled with default or dynamically added values. You have the form submit to send the form data to the server and call the PHP document.

    Your PHP document (second document) must extract data from the form and then you must set up strings that compose the email message if the PHP mail() function is to perform properly. You would extract the form data using name references to the POST associative array, then you just

    The simple PHP tutorial shows you how to print form data, but instead of printing, just set up strings for your email message, and then pass those parameters to the mail() function.

    Your PHP document should also contain a note sent to the form submitter as to whether the form data was emailed successfully or it failed. The mail() function should return a value indicating failure or success, and you use that value to have PHP echo text in the HTML document to be sent, with short body saying "Email successfully sent" or "Email could not be sent (for unknown reasons)".
    Last edited by mavigozler; 08-25-2009 at 11:12 AM. Reason: additional necessary comment

  6. #6
    Join Date
    Aug 2009
    Posts
    4
    Thanks for the reply Mavigozler.

    Eventually I went about passing the variable through the link and getting it with the php $_GET. But as you said,I formated my string through the php code and then sent it through the mail() function. As you said, I made sure that the email was sent successfully and if it was then it would send an alert() and close the form then.

    Thanks again for the informative reply though.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles