Results 1 to 3 of 3
  1. #1
    carag is offline Member
    Join Date
    Jul 2009
    Posts
    4
    Rep Power
    0

    Default need to adjust a code I have to work with hidden fields

    I'm building a form where staff can process quotes. I have a database with products and I need a button in the form to open a new window. In the new window you'd search for your product and choose it. Then I'd like to have a button when after I've clicked it, product code will be filled in the original form and the new window would close.

    This is the code I have that I modified from a code that let you select a value from a select field. Unfortunately it doesn't work. I think the problem is in the head of the child file. I look forward to your comments.


    parent file (parts of it):

    Java Code:
    //head:
    
    <script type="text/javascript">
    targetElement = null;
    function addProduct(frm, id) {
      if(!frm || !id)
        return;
      targetElement = frm.elements[id];
      var handle = window.open('find_product.php');
    }
    </script>
    
    //body:
    
    <form id="frm" name="frm" action="#">
      <input name="code" type="text" id="code" size="10" />
      <input name="name" type="text" id="name" size="32" />
      <input type="button" value="Add Item" onclick="addProduct(this.form, 'code');" />
    </form>

    child file (parts of it):

    Java Code:
    //head:
    
    <script type="text/javascript">
    function addProduct(frm, id) {
      if(!frm || !id)
        return;
      var elem = frm.elements[id];
      if(!elem)
        return;
      var val = elem.options[elem.selectedIndex].value;
      opener.targetElement.value = val;
      this.close();
    }
    </script>
    
    //body:
    
    <form id="frm" name="frm" action="#">
      <input name="code" type="hidden" value="<?php echo $row_rsProducts['ProductID']; ?>" />
      <input name="name" type="hidden" value="<?php echo $row_rsProducts['ProductName']; ?>" />
      <input type="button" value="Add Product" onclick="addProduct(this.form, 'code');" />
    </form>

    Another thing that I'm not sure how to go round is that forms can't be nested so after the field is filled in, how can I submit the value? I'd like to use this same field for another form.

  2. #2
    adz
    adz is offline Member
    Join Date
    Jul 2009
    Posts
    35
    Rep Power
    0

    Default

    Too hard to tell what your code is trying to do. All I can even see are two forms and what appears to be useless JS bar opening a PHP file. Either way what you are after could easily be done with some PHP/simple JS by posting the results back to the page and probably using Ajax I guess to refresh it with the values. If you are taking code you're probably better off keeping it all in one file.

    But yeah, this is a Java forum and not a JS/PHP forum so I think your thread will be closed.

  3. #3
    carag is offline Member
    Join Date
    Jul 2009
    Posts
    4
    Rep Power
    0

    Default

    the code is trying to post results back to the parent page. can you help me solve this?

    this can't be done with php because it's server based. I need to open a new window, find results, post them back to the parent page and close the child window.

Similar Threads

  1. Replies: 6
    Last Post: 02-06-2009, 09:05 PM
  2. how does this code work...explain me the execution please...
    By vital parsley in forum New To Java
    Replies: 3
    Last Post: 07-25-2008, 05:50 AM
  3. the code dosent work
    By pcman in forum Java 2D
    Replies: 1
    Last Post: 03-20-2008, 09:20 PM
  4. Jsp / Java cannot get fields
    By Dracos in forum New To Java
    Replies: 0
    Last Post: 02-04-2008, 10:39 PM
  5. How To:Use a JSlider to adjust Text size in a JPanel
    By louiebagz in forum AWT / Swing
    Replies: 2
    Last Post: 07-01-2007, 08:37 AM

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
  •