2

I have an image in the main.php file :

  <img src="..\images\image.gif" class="cur" onclick="imgWin();">

when I click on this image below function has called :

function imgWin()
{
   imageWin=window.open("../pages/img.php","imageWin","toolbar=no,width=500,height=200,directories=no,menubar=no,SCROLLBARS=yes");
}

this function opens img.php in a new window

img.php file :

<HTML>
<HEAD>
    <TITLE>upload image</TITLE>
</HEAD>
<BODY>

    <FORM NAME="imgForm" method="get" action="#">
          address : 
          <INPUT type="file" name="imgUrl" size="50">
          description : 
          <INPUT type="text" name="description" size="50">
          <input type="submit" value="sumbit">
    </form>
</BODY>
</HTML>

I want to when I click on submit button in above form , data from imgUrl and description textboxes send to main.php file.

How to I can do it ?

KilZone
  • 1,580
  • 9
  • 20
Javad Yousefi
  • 2,250
  • 4
  • 35
  • 52

4 Answers4

1

You should be naming your windows.....

 <form action="foobar.php" method="get" target="foo">
 First name: <input type="text" name="fname" /><br />
 Last name: <input type="text" name="lname" /><br />
 <input type="submit" value="Submit" />
 </form>

This will submit the form back to the target window which is named "foo" and the action is foobar.php ... When you open the window, with your javascript, specify the "name" which is the target ..

 window.open(URL,name,specs,replace)
sdolgy
  • 6,963
  • 3
  • 41
  • 61
0

I suggest you use jQuery to reach it!

// -------------------------- main.php
    <img src="..\images\image.gif" class="cur" id="imgButton">
    <div id="page"></div>

    <script type="text/javascript" >
    $('#imgButton').click(function(){
       $('#page').load('../pages/img.php');
    )}
    </script>


// ------------------img.php file :

    <form name="imgForm" method="post" action="#">
          address : 
          <INPUT type="file" name="imgUrl" size="50">
          description : 
          <INPUT type="text" name="description" size="50">
          <input type="button" value="sumbit" id="submit">
    </form>

        <script type="text/javascript" >
        $('#submit').click(function(){
           ........
           SEND YOUR DATA BY AJAX
           $.ajax({
           url:.......,
           data:(FORM VARIABLES),
           success:function(){
            // PRINT YOUR INPOUT VARIABLE HERE ;
            // $("input[name='imgUrl']").val();

           }
           })

        )}
        </script>

EDIT

$.ajax({  
  type: "POST",  
  url: "YOUR ADDRESS HERE",  
  data: {var1:$("input#[INPUT NAME]").val(),var2:$("input#[INPUT NAME]").val(), ....}  
  success: function() {
  // Do something on success
  // alert ( 'Form Sent' );
  });  
  }  
}); 
Hamid
  • 1,700
  • 2
  • 13
  • 19
-1

The only way I can think of at the moment is to store the required fields of img.php into another file, say img.xml, then load that in the main file using AJAX.

The ajax code would be stored in the main file. In the img.php file, you would have an onClick over the submit button which triggers the AJAX in the main file.

meltuhamy
  • 3,293
  • 4
  • 23
  • 22
-1

Change:

action="#"

To:

action="main.php"

It will send the parameters to main.php and there you need to write code to process it.

Memochipan
  • 3,405
  • 5
  • 35
  • 60