Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2015
    Posts
    3

    Unanswered: Passing parameter from form to light box

    Hai


    I need a help,

    I want to pass value from form to light box....i can pass value to lightbox. but i don't know how to assign form value to php variable in light box...


    My code is


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Light Box</title>
    <script type="text/javascript" language="javascript">
    function displayHideBox(boxNumber)
    {
    if(document.getElementById("LightBox"+boxNumber).s tyle.display=="none")
    {
    document.getElementById("LightBox"+boxNumber).styl e.display="block";
    document.getElementById("grayBG").style.display="b lock";
    var str=document.getElementById('t').value;
    document.getElementById('item2').value=str;

    }
    else {
    document.getElementById("LightBox"+boxNumber).styl e.display="none";
    document.getElementById("grayBG").style.display="n one";
    }
    }
    </script>
    <style>
    .grayBox{
    position: fixed;
    top: 0%;
    left: 0%;
    width: 100%;
    height: 100%;
    background-color: black;
    z-index:1001;
    -moz-opacity: 0.8;
    opacity:.80;
    filter: alpha(opacity=80);
    }
    .box_content {
    position: fixed;
    /*top: 55%;
    left: 50%;
    right: 30%;
    width: 80%;*/
    width:400px;
    height:400px;
    padding: 16px;
    z-index:1002;
    overflow: auto;
    border:solid thin #0C9;
    background-color:#0FC;
    }
    </style>
    </head>
    <body>
    <div id="grayBG" class="grayBox" style="display:none;"></div>
    <div id="LightBox1" class="box_content" style="display:none;">
    <table cellpadding="3" cellspacing="0" border="1" height="300">
    <tr align="left">
    <td colspan="2" bgcolor="#FFFFFF" style="padding:10px;">
    <div onclick="displayHideBox('1'); return false;" style="cursorointer;" align="right">X</div><p>
    <input type="text" id="item2" name="n1" />
    </p>
    </td>
    </tr>
    <tr><td colspan="2">
    </td></tr>
    </table>
    </div>
    <form action="#" method="post" onsubmit="displayHideBox('1');return false">
    <input type="text" id="t" value="" />
    <input type="submit" name="submit" value="submit" />
    </form>
    </body>
    </html>

    any help is appreciated.....

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    JavaScript runs on the client.
    PHP runs on the server.

    If you want to pass a value FROM JS to to PHP then you need to use JS to write the value to a form and then submit the form. This will allow you to pick up the values in PHP using $_POST or $_GET.
    George
    Home | Blog

  3. #3
    Join Date
    Mar 2015
    Posts
    3

    Ok

    Ok....but how i can fetch data from database to lightbox depending on the value pass from form...?....

    I want to fetch data on lightbox....any solutions?...

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Use PHP to get data from database and output the data to screen.
    Code:
    <input type="text" value="<?=SomePHPVariableValueValue?>" id="somedbvalue" />
    Then use JS to pull data out of the rendered HTML output.
    Code:
    var dBValue = document.GetElementById("somedbvalue").value;
    alert(dBValue);
    George
    Home | Blog

  5. #5
    Join Date
    Mar 2015
    Posts
    3

    Reply

    Using the above code, which i posted on here can open lightbox.... and can pass variable from form to lightbox...
    This is i just done by "document.getElementById('item2').value=str;" but i want to assign this value to php variable and using that , i want to fetch data from database..... i think need use ajax to fetch data...

Posting Permissions

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