Results 1 to 6 of 6

Thread: simple, yet complex for newbie

  1. #1
    Join Date
    Aug 2009

    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:

    <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;
    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 >
    <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" >
    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
    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:

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

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

  4. #4
    Join Date
    Aug 2009
    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
    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 10:12 AM. Reason: additional necessary comment

  6. #6
    Join Date
    Aug 2009
    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



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.13867 seconds
  • Memory Usage 2,912KB
  • Queries Executed 15 (?)
More Information
Template Usage (35):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (2)bbcode_code
  • (2)bbcode_html
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (6)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (73):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates