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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Regular Coder howie2009's Avatar
    Join Date
    May 2009
    Location
    Ireland
    Posts
    204
    Thanks
    37
    Thanked 0 Times in 0 Posts

    setting of text field value to that of url

    Hi Guys,
    If you click the link on http://www.thefreeadswebsite.com/popup.html a form pops up. How do I set the value of the URL text field in the form to be equal to the url of the page it originated for i.e in this instance it the value would be http://www.thefreeadswebsite.com/popup.htm. Window.location i believe would set the value to the current url. What I need is the value of the url the pop up originated from.

    THANKS

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    I believe this should do what you want.

    Code:
    if (window.opener && !window.opener.closed)
    {
        var parent_uri = window.opener.location;
    }

  • Users who have thanked MattF for this post:

    howie2009 (07-25-2009)

  • #3
    Regular Coder howie2009's Avatar
    Join Date
    May 2009
    Location
    Ireland
    Posts
    204
    Thanks
    37
    Thanked 0 Times in 0 Posts
    Hi,

    How would I integrate it into the attached please?
    eg
    td>URL Of Ad&nbsp;*</td>
    <td colspan="2"><input name=field_7 type=text id=field_7 value='parent_uri' size='60' maxlength="255" /></td> </tr>
    ???
    Very new to this stuff.
    THANKS

    [code]
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <!-- This page is copyright Elated Communications Ltd. (www.elated.com) -->

    <title>JavaScript accordion example</title>

    <style type="text/css">
    body { font-size: 80%; font-family: 'Lucida Grande', Verdana, Arial, Sans-Serif; }
    .accordionItem h2 { margin: 0; font-size: 1.1em; padding: 0.4em; color: #0000ff; background-color: #fff; border-bottom: 1px solid #fff; }
    .accordionItem h2:hover { cursor: pointer; }
    .accordionItem div { margin: 0; padding: 1em 0.4em; background-color: #fff; border-bottom: 1px solid #fff; }
    .accordionItem.hide h2 { color: #0000ff; background-color: #fff; }
    .accordionItem.hide div { display: none; }
    </style>

    <script type="text/javascript">
    //<![CDATA[
    function addLoadEvent(func)
    {
    var oldonload = window.onload;
    if (typeof window.onload != 'function')
    {
    window.onload = func;
    }
    else
    {
    window.onload = function()
    {
    oldonload();
    func();
    }
    }
    }

    addLoadEvent(init);


    var accordionItems = new Array();

    function init() {

    // Grab the accordion items from the page
    var divs = document.getElementsByTagName( 'div' );
    for ( var i = 0; i < divs.length; i++ ) {
    if ( divs[i].className == 'accordionItem' ) accordionItems.push( divs[i] );
    }

    // Assign onclick events to the accordion item headings
    for ( var i = 0; i < accordionItems.length; i++ ) {
    var h2 = getFirstChildWithTagName( accordionItems[i], 'H2' );
    h2.onclick = toggleItem;
    }

    // Hide all accordion item bodies except the first
    for ( var i = 0; i < accordionItems.length; i++ ) {
    accordionItems[i].className = 'accordionItem hide';
    }

    }

    function toggleItem() {
    var itemClass = this.parentNode.className;

    // Hide all items
    for ( var i = 0; i < accordionItems.length; i++ ) {
    accordionItems[i].className = 'accordionItem hide';
    }

    // Show this item if it was previously hidden
    if ( itemClass == 'accordionItem hide' ) {
    this.parentNode.className = 'accordionItem';
    }
    }

    function getFirstChildWithTagName( element, tagName ) {
    for ( var i = 0; i < element.childNodes.length; i++ ) {
    if ( element.childNodes[i].nodeName == tagName ) return element.childNodes[i];
    }
    }

    //]]>
    </script>

    <style type="text/css">
    <!--
    .style1 {
    color: #0000FF;
    font-size: 10em;
    }
    .style2 {color: #0000FF}
    -->
    </style>
    </head>

    <h1>&nbsp;</h1>

    <div class="accordionItem">
    <h2 class="style1"><img src="../Edit_No.png" alt="" width="64" height="64" /> Click Here To Report This Ad </h2>
    <div>
    <form method=post enctype=multipart/form-data action=report_ad_form/processor.php onSubmit="return validatePage1();">
    <table width="663" border="0" cellpadding="6" cellspacing="0" bordercolor="#FFFFFF">
    <tr>
    <td width="254"><label>Is This Ad Illegal?</label>
    <span> </span></td>
    <td width="92"><span>
    <input type=checkbox name=field_1[]2 id=field_1_option_1 value="Yes" />
    <label class=formFieldOption for="field_1_option_1">Yes</label>
    </span></td>
    <td width="281"><span>
    <label class=formFieldOption for="field_1_option_2"></label>
    </span></td>
    </tr>
    <tr>
    <td><label>Is This Ad Offensive?</label>
    <span></span></td>
    <td><span>
    <input type=checkbox name=field_2[]2 id=field_2_option_1 value="Yes" />
    <label class=formFieldOption for="field_2_option_1">Yes</label>
    </span></td>
    <td><span>
    <label class=formFieldOption for="field_2_option_2"></label>
    </span></td>
    </tr>
    <tr>
    <td><label>Is This Ad A Duplicate?</label>
    <span></span></td>
    <td><span>
    <input type=checkbox name=field_3[]2 id=field_3_option_1 value="Yes" />
    <label class=formFieldOption for="field_3_option_1">Yes</label>
    </span></td>
    <td><span>
    <label class=formFieldOption for="field_3_option_2"></label>
    </span></td>
    </tr>
    <tr>
    <td><label>Is This Ad Inaccurate?</label>
    <span></span></td>
    <td><label></label>
    <span>
    <input type=checkbox name=field_4[]2 id=field_4_option_1 value="Yes" />
    <label class=formFieldOption for="field_4_option_1">Yes</label>
    </span></td>
    <td><span>
    <label class=formFieldOption for="field_4_option_2"></label>
    </span></td>
    </tr>
    <tr>
    <td>Your Name</td>
    <td colspan="2"><input type=text name=field_5 id=field_5 size='50' value='' /></td>
    </tr>
    <tr>
    <td><label>Your Email</label></td>
    <td colspan="2"><input type=email name=field_6 id=field_6 size=45 style="background-image:url(imgs/email.png); background-repeat: no-repeat; padding: 2px 2px 2px 25px;" /></td>
    </tr>
    <tr>
    <td>URL Of Ad&nbsp;*</td>
    <td colspan="2"><input name=field_7 type=text id=field_7 value='{site_url}ads_details.php?item_id={item_id}' size='60' maxlength="255" /></td>
    </tr>
    <tr>
    <td><label>Please Explain The Issue&nbsp;*</label></td>
    <td colspan="2"><textarea name=field_8 id=field_8 rows=4 cols=40></textarea></td>
    </tr>
    <tr>
    <td>Validation Image: </td>
    <td colspan="2"><a class=info href=#><img src="report_ad_form/CaptchaSecurityImages.php" alt="For Security Purpose Please Type In The Letters In The Image" /></a></td>
    </tr>
    <tr>
    <td>Type The Validation Image Characters:</td>
    <td colspan="2"><input id="captchaForm" name="security_code" class="mainForm" type="text"/></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td colspan="2"><input name="submit" type="submit" class="mainForm" id="saveForm" value="Submit" />
    *<span class="style2">required input </span></td>
    </tr>
    </table>


    <!-- end of this page -->

    <!-- page validation -->
    <SCRIPT type=text/javascript>
    <!--
    function validatePage1()
    {
    retVal = true;
    if (validateField('field_1','fieldBox_1','checkbox',0) == false)
    retVal=false;
    if (validateField('field_2','fieldBox_2','checkbox',0) == false)
    retVal=false;
    if (validateField('field_3','fieldBox_3','checkbox',0) == false)
    retVal=false;
    if (validateField('field_4','fieldBox_4','checkbox',0) == false)
    retVal=false;
    if (validateField('field_5','fieldBox_5','text',0) == false)
    retVal=false;
    if (validateField('field_6','fieldBox_6','email',0) == false)
    retVal=false;
    if (validateField('field_7','fieldBox_7','text',1) == false)
    retVal=false;
    if (validateField('field_8','fieldBox_8','textarea',1) == false)
    retVal=false;

    if(retVal == false)
    {
    alert('Please correct the errors. Fields marked with an asterisk (*) are required, Validation Image characters must be entered correctly and Email format must be correct.');
    return false;
    }
    return retVal;
    }
    //-->
    </SCRIPT>
    <SCRIPT type=text/javascript>
    <!--
    function collapseElem(obj)
    {
    var el = document.getElementById(obj);
    el.style.display = 'none';
    }


    function expandElem(obj)
    {
    var el = document.getElementById(obj);
    el.style.display = '';
    }


    //-->
    </SCRIPT>
    <!-- expand/collapse function -->


    <!-- expand/collapse function -->
    <SCRIPT type=text/javascript>
    <!--

    // collapse all elements, except the first one
    function collapseAll()
    {
    var numFormPages = 1;

    for(i=2; i <= numFormPages; i++)
    {
    currPageId = ('mainForm_' + i);
    collapseElem(currPageId);
    }
    }


    //-->
    </SCRIPT>
    <!-- expand/collapse function -->


    <!-- validate -->
    <SCRIPT type=text/javascript>
    <!--
    function validateField(fieldId, fieldBoxId, fieldType, required)
    {
    fieldBox = document.getElementById(fieldBoxId);
    fieldObj = document.getElementById(fieldId);

    if(fieldType == 'text' || fieldType == 'textarea' || fieldType == 'password' || fieldType == 'file' || fieldType == 'phone' || fieldType == 'website')
    {
    if(required == 1 && fieldObj.value == '')
    {
    fieldObj.setAttribute("class","mainFormError");
    fieldObj.setAttribute("className","mainFormError");
    fieldObj.focus();
    return false;
    }

    }


    else if(fieldType == 'menu' || fieldType == 'country' || fieldType == 'state')
    {
    if(required == 1 && fieldObj.selectedIndex == 0)
    {
    fieldObj.setAttribute("class","mainFormError");
    fieldObj.setAttribute("className","mainFormError");
    fieldObj.focus();
    return false;
    }

    }


    else if(fieldType == 'email')
    {
    if((required == 1 && fieldObj.value=='') || (fieldObj.value!='' && !validate_email(fieldObj.value)))
    {
    fieldObj.setAttribute("class","mainFormError");
    fieldObj.setAttribute("className","mainFormError");
    fieldObj.focus();
    return false;
    }

    }



    }

    function validate_email(emailStr)
    {
    apos=emailStr.indexOf("@");
    dotpos=emailStr.lastIndexOf(".");

    if (apos<1||dotpos-apos<2)
    {
    return false;
    }
    else
    {
    return true;
    }
    }


    function validateDate(fieldId, fieldBoxId, fieldType, required, minDateStr, maxDateStr)
    {
    retValue = true;

    fieldBox = document.getElementById(fieldBoxId);
    fieldObj = document.getElementById(fieldId);
    dateStr = fieldObj.value;


    if(required == 0 && dateStr == '')
    {
    return true;
    }


    if(dateStr.charAt(2) != '/' || dateStr.charAt(5) != '/' || dateStr.length != 10)
    {
    retValue = false;
    }

    else // format's okay; check max, min
    {
    currDays = parseInt(dateStr.substr(0,2),10) + parseInt(dateStr.substr(3,2),10)*30 + parseInt(dateStr.substr(6,4),10)*365;
    //alert(currDays);

    if(maxDateStr != '')
    {
    maxDays = parseInt(maxDateStr.substr(0,2),10) + parseInt(maxDateStr.substr(3,2),10)*30 + parseInt(maxDateStr.substr(6,4),10)*365;
    //alert(maxDays);
    if(currDays > maxDays)
    retValue = false;
    }

    if(minDateStr != '')
    {
    minDays = parseInt(minDateStr.substr(0,2),10) + parseInt(minDateStr.substr(3,2),10)*30 + parseInt(minDateStr.substr(6,4),10)*365;
    //alert(minDays);
    if(currDays < minDays)
    retValue = false;
    }
    }

    if(retValue == false)
    {
    fieldObj.setAttribute("class","mainFormError");
    fieldObj.setAttribute("className","mainFormError");
    fieldObj.focus();
    return false;
    }
    }
    //-->
    </SCRIPT>

    <!-- end page validaton -->



    <!-- next page buttons -->
    </form></p>
    </div>
    </div>

    <div class="accordionItem">
    <h2>&nbsp;</h2>
    </div>

    <p><a href="/articles/javascript-accordion/"></a></p>

    </body>
    </html>

    [code]
    Last edited by howie2009; 07-25-2009 at 10:30 PM.

  • #4
    Regular Coder howie2009's Avatar
    Join Date
    May 2009
    Location
    Ireland
    Posts
    204
    Thanks
    37
    Thanked 0 Times in 0 Posts
    Hi,
    ...or even a basic sample of a basic pop up showing the url from the originating page in a text field. I want to build a report ad feature.
    THANKS!

  • #5
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Code:
    <td colspan="2"><input name=field_7 type=text id=field_7 value="" onload="if (parent_uri) this.value=parent_uri;" size='60' maxlength="255" /></td> </tr>
    I believe the above should enter the value in the input value field.

  • Users who have thanked MattF for this post:

    howie2009 (07-26-2009)

  • #6
    Regular Coder howie2009's Avatar
    Join Date
    May 2009
    Location
    Ireland
    Posts
    204
    Thanks
    37
    Thanked 0 Times in 0 Posts
    Ok Matt Thanks for your help.

    I wrote this script at the top

    <SCRIPT type=text/javascript>

    if (window.opener && !window.opener.closed)
    {
    var parent_uri = window.opener.location;
    }
    </SCRIPT>

    and altered the input section as above but the url textbox (http://www.thefreeadswebsite.com/ire...ab_example.htm) is empty. It must be me doing the script wrong or in the wrong place.

  • #7
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Judging by that link you posted, (note that javascript isn't my strong point, btw), you're not actually opening a child window but just generating the form within the current window when that report link is activated, are you not?

  • #8
    Regular Coder howie2009's Avatar
    Join Date
    May 2009
    Location
    Ireland
    Posts
    204
    Thanks
    37
    Thanked 0 Times in 0 Posts
    Hi,

    I wrote in an alert

    if (window.opener && !window.opener.closed)
    {
    var parent_uri = window.opener.location;
    alert('Test'+parent_uri);
    }
    </SCRIPT>

    an the alert shows the url perfectly! THANKS!

    Just trying to get the URL field to show the url now. Hmmmmm

    Really close!

  • #9
    Regular Coder howie2009's Avatar
    Join Date
    May 2009
    Location
    Ireland
    Posts
    204
    Thanks
    37
    Thanked 0 Times in 0 Posts
    Hi Matt I am generating the pop up form from http://www.thefreeadswebsite.com/popup.html

  • #10
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    That buggers up my previous theory then. Try onfocus instead of onload and see if the value appears in that input field when you focus, (click on), the input field.

  • #11
    Regular Coder howie2009's Avatar
    Join Date
    May 2009
    Location
    Ireland
    Posts
    204
    Thanks
    37
    Thanked 0 Times in 0 Posts
    Ya onfocus works. Thanks
    Agonisingly close!

  • #12
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Try:

    Code:
    if (window.opener && !window.opener.closed)
    {
        var parent_uri = window.opener.location;
    
        if (document.getElementById('field_7'))
        {
            document.getElementById('field_7').value = parent_uri;
        }
    }
    Not sure if the syntax will need to be slightly different or not with it being a form field.

  • #13
    Regular Coder howie2009's Avatar
    Join Date
    May 2009
    Location
    Ireland
    Posts
    204
    Thanks
    37
    Thanked 0 Times in 0 Posts
    unfortunately not working with onload. Onfocus is perfect. Thanks

  • #14
    Regular Coder howie2009's Avatar
    Join Date
    May 2009
    Location
    Ireland
    Posts
    204
    Thanks
    37
    Thanked 0 Times in 0 Posts
    Really strange that the onload doesnt work

  • #15
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    I think you'd need to place that script block below that form field in the source for it to insert the value without using the onload/onfocus selector.

    As I say, however, there may be something else needed also with regards to the code, but try moving that script block further down the page.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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