SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to get value from popup window

    Hi,
    I would like to open a hidden popup window to pass value when user enter the value on the textbox. The popup window will perform operation that call the javabean to retrieve values to be displayed on the form that open the window.

    how to pass values from popup window to the form

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,812
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    You have put this in the Javascript forum but make reference to javabeans.

    Are you trying to use Javascript to pass information between windows or are you trying to use Java?
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How to assign value to the form field (I have retrieve the value from the db)

  4. #4
    SitePoint Member
    Join Date
    Sep 2005
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tllcll
    How to assign value to the form field (I have retrieve the value from the db)
    If you are using server side scripting, when you generate your page try to use some crap like this:

    PHP Code:
    jsp
    <input type="text" value="<%= myValueFromServerSide %>" />
    or for php
    <input type="text" value="<?= myValueFromServerSide ?>" />
    for example in JSP, or PHP you'd have this syntax, for ASP i have no clue, coz I never used it in my 8 year life.

    Or if you're refering to JavaScript:
    PHP Code:
    function assignValueToTextField(value)
    {
      var 
    myTextField document.getElementById("myTextField");
      if(
    myTextField != null)
      {
        
    myTextField.value value;
      }
    }

    and 
    on HTML page you'll have text field defined like this:

    <input type="text" id="myTextField" /> 


  5. #5
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the example.

    if 1 have my page called test.jsp and in this page 1 have many fields. upon user enter the value on the first field, the value of the second field will change.

    in test.jsp, I have the following
    <input type="text" name="code" value"" />
    <input type="text" name="desc" value="<%=myValueFromServerSide %>" />

    when user enters the value for 'code', i will have to pass the value to javabean to process (where I think of using hidden popup or something so that I can get the value in java format) and then return the value to display in 'desc' on the page.

    so, when should I call the function 'assignValueToTextField(this)'

  6. #6
    SitePoint Member
    Join Date
    Sep 2005
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, you have several ways to do it, first and most bloated, and most suggested will be is to use some crap like XMLhttpsRequet or some crap like that . What you might do, is create an iframe dynamically, when user changes something, and in that iframe, load additioanal JSP page, with approporiate parameters, and then, read an output (output could be xml, or simple html, or just plain text, anyway u want) and populate text field.

  7. #7
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you provide me with sample coding based on this case

  8. #8
    SitePoint Addict ruchit's Avatar
    Join Date
    Sep 2005
    Location
    miDDle oF NoWHere
    Posts
    222
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HTML Code:
    <script language="javascript">
    function getValue(objText) {
      window.open("popUp.jsp?code="+objText.value,"", "width=100, height=100, top=300, left=300, menubar=no, scrollbars=no");
      window.focus();
    }
    </script>
    <input type="text" name="code" value="" onChange="javascript:getValue(this)" />
    <input type="text" name="desc" value="" />
    now in the pop(ed) up window... the i've taken for this is popup.jsp you can output this
    <script language="javascript">
    window.opener.assignValueToTextField(<%=myValueFromServerSide %>);
    window.close();
    </script>
    work together - make world a better place
    Outsource to India
    Web Design India
    Affordable Webhosting

  9. #9
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dont really get you. Is the following correct. if it is, where do put the code to retrieve the value of desc from server based on the code (which is in jsp format)

    test.jsp
    ======

    <script language="javascript">

    function assignValueToTextField(value)
    {
    var desc = document.getElementById("desc");
    if(desc != null)
    {
    desc.value = value;
    }
    }

    function getValue(objText) {
    window.open("popUp.jsp?code="+objText.value,"", "width=100, height=100, top=300, left=300, menubar=no, scrollbars=no");
    window.focus();
    }

    </script>

    <input type="text" name="code" value="<%= myValueFromServerSide %>" onChange="javascript:getValue(this)" />
    <input type="text" name="desc" value="" />

    popUp.jsp
    =======
    <script language="javascript">
    window.opener.assignValueToTextField(<%=myValueFromServerSide %>);
    window.close();
    </script>

  10. #10
    SitePoint Member
    Join Date
    Sep 2005
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you didnt get this figured out, let me know and I'll post working example for your convenies..
    -- benz.amg

    P.S. I was super busy all this time, didnt check forum


Bookmarks

Posting Permissions

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