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.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    send value javascript help

    Hello folks, I’m not familiar with editing JavaScript code and was wondering if anyone can help? I’m trying to populate a text field in a form with values from a popup or DHTML window. Similar to a popup calendar selection function.

    The text field reference I want populated from a popup list of items looks like this:

    <input type=text name=b[optional_field_1] id=optional_field_1 value="">

    I can't seem to reference the "name=" in the javascript because it has [] in it. So I tried to reference the id.

    I call the popup window with:

    <a href="#" onClick="window.open('http://mysite.com/popup-file.php','popuppage','width=550,height=500,top=20,left=100,scrollbars=1,resizable=1,toolbar=1,locat ion=1,menubar=1');">Select Make</a>

    and use this to send the selected value back to the text field:

    <SCRIPT LANGUAGE="JavaScript">

    function populate_parent_formfield(val)
    {
    alert("val: " + val)//make sure that it is what you chose in the pop-up window select box; remove once verified

    var elarray = window.opener.document.classified_details_form.elements;

    for(var i = 0; i < elarray.length; i++)
    {
    if(elarray[i].id == "optional_field_1")
    {elarray[i].value = val; break;}
    }
    }
    </script>

    this is the popup window button to send back the value:

    <input type=button value="Add Make" onClick="populate_parent_formfield(document.selectform.elements['selectmenu'].selectedIndex.value)" name="button">

    This is as far as I could get with help from others. Any suggestions on what might be missing would be greatly appreciated. Can id’s be referenced or is there another/better way to send the value back to the text field?

    Thanks in advance,

    Shawn

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: send value javascript help

    Originally posted by soquinn
    I can't seem to reference the "name=" in the javascript because it has [] in it. So I tried to reference the id.
    You don't have to take the workaround, you can reference names with brackets in them:

    <input type="text" name="b[optional_field_1] " id="optional_field_1" value="" />

    reference it like

    var val = document.forms["nameOfForm"].elements["b[optional_field_1]"].value;

    Hope that helps anything, I haven't looked closely enough into your following problems, but as I said, I doubt this workaround is necessary at all.
    De gustibus non est disputandum.

  • #3
    New to the CF scene
    Join Date
    Jun 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the relpy mordred... no one has mentioned this to me before... can I ask you to please send me an example of all the code that would replace this:

    <SCRIPT LANGUAGE="JavaScript">
    function populate_parent_formfield(val)
    {
    alert("val: " + val)//make sure that it is what you chose in the pop-up window select box; remove once verified

    var elarray = window.opener.document.classified_details_form.elements;

    for(var i = 0; i < elarray.length; i++)
    {
    if(elarray[i].id == "optional_field_1")
    {elarray[i].value = val; break;}
    }
    }
    </script>


    Thanks,

    Shawn


  •  

    Posting Permissions

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