By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,730 Members | 1,567 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,730 IT Pros & Developers. It's quick & easy.

part of data gets lost after refresh

100+
P: 110
User selects choclates code and qty to be produced is entered by the user
depending upon the packing of choclates the table is shown where again the produced qty is divided betwwen packing.

once the user clicks ok button
below code should get executed afte this
data is fetched from mysql table and displayed in the below table once refreshed
and i'm passing choclate code but not passing packing list details in javascript so it get blank
now depending upon the items required for making the choclate which independent of packing list is displayed in the table

to overcome this i want to use iframe where in only part of the document gets refreshed .
i can somebosy tell me how to do this?
Oct 29 '07 #1
Share this Question
Share on Google+
27 Replies


acoder
Expert Mod 15k+
P: 16,027
Post the code which is causing the problem.
Oct 29 '07 #2

100+
P: 110
Post the code which is causing the problem.
above this i have combo box from where choclates are selected and then the qty to be produced is taken and after that the following code is done
which list the choclates depending upon the packing given to the choclates
and the number of packs of particualr pack is entered there
the total qty produced is distributed for different packs . this is in the while loop upto this is ok

[HTML]<table>
<tr>
<td width="5"><input type="text" value="<?=$packcode?>" name='<?="packcode[".$i."]"?>' id='<?="packcode[".$i."]"?>' size="8" maxlength="8" ></td>
<td colspan="2"><input type="text" value="<?=$pack_name?>" name='<?="pack_name[".$i."]"?>' id='<?="pack_name[".$i."]"?>' size="60" maxlength="60" readonly="Y"> <td><input type="text" value="<?=$p_pack?>" name='<?="p_pack[".$i."]"?>' size="6" id='<?="p_pack[".$i."]"?>' class="dlight" maxlength="10" readonly="y" ><input type="text" value="<?=$punit?>" name='<?="punit[".$i."]"?>' size="6" id='<?="punit[".$i."]"?>' class="dlight" maxlength="12" readonly="y"></td> <td><input type="text" value="<?=$packsize?>" id='<?="packzise[".$i."]"?>' name='<?="packsize[".$i."]"?>' tabindex="5" size="6" maxlength="12" onblur="chkqty(this.value,'<?=$mp_pack?>','<?=$i?> ');" onFocus="chkbtqty('<?=$i?>');"></td> <td><input type="text" value="<?=$qty?>" name='<?="qty[".$i."]"?>' id='<?="qty[".$i."]"?>' size="6" maxlength="12" readonly="y"></td></tr>
<? $i++;
} //this is the while loop to show pack list ?>
<td><input type="button" name="ok" value="OK" onClick="prodqty('<?prodqty?>',this.value,'<?=$mod e?>');"></td>
<?
//now after clicking ok button i want that items required for this choclate should be displayed here but when i do that without frames it shows the table with items details but my page gets refreshed my packing list table values i have enetered becomes blank i have used javasccript passing values but i have not passed packing split items code to the url
if($ok=="OK"){
//i was trying to use frames but just new to this
?>

<iframe name="FRAMENAME" src="ini.php" width="50" height="100" frameborder="1" scrolling="YES" hspace="20" vspace="10" >
</iframe><? }?>


<table>
<tr>
<td colspan="7"> <div align="center">
<input type="button" name="save" value="Save" tabindex="16" onClick="javascript:saveicde();">
<input type="button" name="cancel" value="Cancel" tabindex="17" onClick="javascript:cancelicde();">
</div></td>
</tr>
</table>
<?
}
}
?>
</table>[/HTML]




Expand|Select|Wrap|Line Numbers
  1. function passprodqty(prodqty,ok,mode){
  2.     prodqty=parseInt(document.getElementById("mprodqty").value);
  3. //choclate code but not packing code
  4.     cde=document.getElementById("cde").value;
  5.     newurl="http://localhost//init.php?mode="+mode+"&cde="+cde+"&mprodqty="+prodqty+"&ok="+ok;
  6.     document.location.href=newurl;
  7. }
Oct 30 '07 #3

acoder
Expert Mod 15k+
P: 16,027
Instead of using frames, use Ajax for this. See an example.
Oct 30 '07 #4

100+
P: 110
Thanks a lot
but i have managed to do this with iframes only
but now want to know if there are any issues regarding saving of data in iframes from the file refred in iframe and the main form ?
Nov 7 '07 #5

acoder
Expert Mod 15k+
P: 16,027
What kind of issues are you worried about?
Nov 7 '07 #6

100+
P: 110
I remember reading somewhere iframes creates problem during saving of data
Nov 7 '07 #7

acoder
Expert Mod 15k+
P: 16,027
One possible problem might be that a history entry is created.

Have you experienced any problems so far?
Nov 7 '07 #8

100+
P: 110
as given below my main form gives chocltes list depending upon the packing type have given a ok button whcih generates below data in iframe

now after this i have used a iframe which shows list of raw material required for the product and qty

and the list of packing material for each packing type product
which can be more then one
( i have made another php file for this which is referred in iframe)


then in the main form i have submit button which when clicked saves the data from the main form but problem is where do i save the data from my file referred in iframe i tired giving submit button there also n tried to insert data but giving me problem


thanks
Nov 16 '07 #9

acoder
Expert Mod 15k+
P: 16,027
The whole point of using the iframe was, I thought, to avoid the whole page being unloaded and the submit being made client-side.

Can you show the code for ini.php (iframe file) and what needs saving.
Nov 16 '07 #10

100+
P: 110
[PHP]
//here i'm mtrying to post my data in the raw material table but i'm getting the //count of the raw material as 0 then it doesnt post properly
$num=count($_POST['mrcde']);
for($idx=0;$idx<$num;$idx++){
$mrcde=$_POST['mrcde'][$idx];
$mrname=$_POST['mrname'][$idx];
$qtyreqd=$_POST['qtyreqd'][$idx];
}
//i click on submit button givene in down n then want to post the details
//i have another submit button on the main page which saves the data from the main form
//where am i going wrong

<form method="POST" name="ini">
<h1>Raw material</h1><table border="1">
<tr>
<thead><th>Code</th><th>Material </th><th>Units</th><th>Qty</th><th>Available Qty</th></thead></tr>
<?
$k=0;
//here i ha ve a query to get the details from table and display it in the table form similarily next i create a table for packing material required for the product
</tr>
<tr><td><input type="submit" name="save" value="Save" ></td></tr>
</table>
</form>

</body>
</html>[/PHP]
Nov 17 '07 #11

acoder
Expert Mod 15k+
P: 16,027
There's no action attribute for the form. Where does it post to?
Nov 17 '07 #12

100+
P: 110
I changed it to [PHP]<form name="ini" method="POST" action=ini.php">
[/PHP]
but it just refreshes ini.php now only with raw list but does not alert num of records i'm counting of raw code
i'm stuck up with this
Nov 19 '07 #13

acoder
Expert Mod 15k+
P: 16,027
You're using the iframe to avoid the refresh problem, so you should use the data retrieved in the iframe to update the main page and that is what should be submitted. You can't submit the iframe page at the same time as the main page.
Nov 19 '07 #14

100+
P: 110
as i said i'm new to this iframe concept how do i submit the data from iframe to the main page can u just help me with my example without having to give one separate save button on the iframe page


thanks
Nov 19 '07 #15

acoder
Expert Mod 15k+
P: 16,027
You don't need to submit the data. Add it to the main page either as visible form elements or as hidden fields. Can you show the data that needs to be submitted?
Nov 19 '07 #16

100+
P: 110
[PHP]
//this is the data which is generated in the iframe file i want to post to the main form(main.php) and save in the mysql table

for($idx=0;$idx<$count($mrcde);$idx++){
$mrcde=$_POST['mrcde'][$idx];
$mrname=$_POST['mrname'][$idx];
$qtyreqd=$_POST['qtyreqd'][$idx];
}
//i click on submit button givene in down n then want to post the details
//i have another submit button on the main page which saves the data from the main form
//where am i going wrong

<form method="POST" name="ini">
<h1>Raw material</h1><table border="1">
<tr>
<thead><th>Code</th><th>Material </th><th>Units</th><th>Qty</th><th>Available Qty</th></thead></tr>
<?
$k=0;

//here i have a query to get the details from table and display it in the table form similarily next i create a table for packing material required for the product .
<tr>
<td width="5"><input type="text" value="<?=$mrcde?>" name='<?="mrcde[".$k."]"?>' id='<?="mrcde[".$k."]"?>' maxlength="6" disabled readonly="y"></td>
<td colspan="2"><input type="text" value="<?=$mrname?>" name='<?="mrname[".$k."]"?>' id='<?="mrname[".$k."]"?>' maxlength="60" disabled readonly="y"></td>
<td><input type="text" value="<?=$qtyreqd?>" name='<?="qtyreqd[".$k."]"?>' id='<?="qtyreqd[".$k."]"?>' disabled readonly="y" ></td>
</tr>
<tr><td><input type="submit" name="save" value="Save" ></td></tr>
</table>
</form>

</body>
</html>[/PHP]
Nov 20 '07 #17

acoder
Expert Mod 15k+
P: 16,027
Add these fields to the main page, perhaps as hidden fields.

Give your iframe a name and then access it using frames['iframename'].

To access the document/input elements within the iframe:
Expand|Select|Wrap|Line Numbers
  1. var iframe = frames['iframename'];
  2. var form = iframe.document.forms["ini"];
  3. code = // whatever code is called
  4. // and likewise for the rest
Nov 20 '07 #18

100+
P: 110
[PHP]
//this is the data which is generated in the iframe file(INI.PHP) i want to post to the main form(main.php) and save in the mysql table

for($idx=0;$idx<$count($mrcde);$idx++){
$mrcde=$_POST['mrcde'][$idx];
$mrname=$_POST['mrname'][$idx];
$qtyreqd=$_POST['qtyreqd'][$idx];
}
//i click on submit button givene in down n then want to post the details
//i have another submit button on the main page which saves the data from the main form
//where am i going wrong

<form method="POST" name="ini">
<h1>Raw material</h1><table border="1">
<tr>
<thead><th>Code</th><th>Material </th><th>Units</th><th>Qty</th><th>Available Qty</th></thead></tr>
<?
$k=0;
$sqlraw="select A.*,B.* from material a,trlist b where a.code=b.code && a.packcode='$mcode'";
$queryraw=mysql_query($sqlraw);
WHILE($CONDITION){
<tr>
<td width="5"><input type="text" value="<?=$mrcde?>" name='<?="mrcde[".$k."]"?>' id='<?="mrcde[".$k."]"?>' maxlength="6" disabled readonly="y"></td>
<td colspan="2"><input type="text" value="<?=$mrname?>" name='<?="mrname[".$k."]"?>' id='<?="mrname[".$k."]"?>' maxlength="60" disabled readonly="y"></td>
<td><input type="text" value="<?=$qtyreqd?>" name='<?="qtyreqd[".$k."]"?>' id='<?="qtyreqd[".$k."]"?>' disabled readonly="y" ></td>
</tr>
}
<tr><td><input type="submit" name="save" value="Save" ></td></tr>
</table>
</form>

</body>
</html>


//main.php

<table>
<tr>
<td width="5"><input type="text" value="<?=$packcode?>" name='<?="packcode[".$i."]"?>' id='<?="packcode[".$i."]"?>' size="8" maxlength="8" ></td>
<td colspan="2"><input type="text" value="<?=$pack_name?>" name='<?="pack_name[".$i."]"?>' id='<?="pack_name[".$i."]"?>' size="60" maxlength="60" readonly="Y"> <td><input type="text" value="<?=$p_pack?>" name='<?="p_pack[".$i."]"?>' size="6" id='<?="p_pack[".$i."]"?>' class="dlight" maxlength="10" readonly="y" ><input type="text" value="<?=$punit?>" name='<?="punit[".$i."]"?>' size="6" id='<?="punit[".$i."]"?>' class="dlight" maxlength="12" readonly="y"></td> <td><input type="text" value="<?=$packsize?>" id='<?="packzise[".$i."]"?>' name='<?="packsize[".$i."]"?>' tabindex="5" size="6" maxlength="12" onblur="chkqty(this.value,'<?=$mp_pack?>','<?=$i?> ');" onFocus="chkbtqty('<?=$i?>');"></td> <td><input type="text" value="<?=$qty?>" name='<?="qty[".$i."]"?>' id='<?="qty[".$i."]"?>' size="6" maxlength="12" readonly="y"></td></tr>
<? $i++;
} //this is the while loop to show pack list ?>
<td><input type="button" name="ok" value="OK" onClick="prodqty('<?prodqty?>',this.value,'<?=$mod e?>');"></td>
<?
if($ok=="OK"){
?>

<iframe name="iframe1" src="ini.php" width="50" height="100" frameborder="1" scrolling="YES" hspace="20" vspace="10" >
</iframe><?

//do i have to put the code for generating the table which i have used in ini.php here and make the fields hidden
and then
var iframe = frames['iframe1'];
var form = iframe1.document.forms["ini"];
for($j=0;$j<count(form.mrcde);$j++){
mrcde=$_POST['mrcde'][$j];
mrname=$_POST['mrname'][$j];
$qtyreqd=$_POST['qtyreqd'][$j];
<tr>
<td width="5"><input type="hidden" value="<?=$mrcde?>" name='<?="mrcde[".$j."]"?>' id='<?="mrcde[".$j."]"?>'></td>
<td colspan="2"><input type="hidden" value="<?=$mrname?>" name='<?="mrname[".$j."]"?>' id='<?="mrname[".$j."]"?>'></td>
<td><input type="hidden" value="<?=$qtyreqd?>" name='<?="qtyreqd[".$j."]"?>' id='<?="qtyreqd[".$j."]"?>'></td>
</tr>


}


}?>



<table>
<tr>
<td colspan="7"> <div align="center">
<input type="button" name="save" value="Save" tabindex="16" onClick="javascript:savecde();">
<input type="button" name="cancel" value="Cancel" tabindex="17" onClick="javascript:cancelcde();">
</div></td>
</tr>
</table>
<?
}
}
?>
</table>[/PHP]
Nov 21 '07 #19

acoder
Expert Mod 15k+
P: 16,027
You won't be able to mix the JavaScript and PHP like that.

Put the JavaScript code in a function which is called onsubmit or whenever you want to get the data from the iframe before submitting.

The fields don't need to be hidden - that's up to you.
Nov 21 '07 #20

100+
P: 110
how do i write a javascript function on the save button onclick button or onsubmit event of the ini.php in the iframe or should i write it in the save button on the main form
but how do i send the count of the mrcde to the main form

i'm getting confused


thanks in advance
Nov 21 '07 #21

acoder
Expert Mod 15k+
P: 16,027
how do i write a javascript function on the save button onclick button or onsubmit event of the ini.php in the iframe or should i write it in the save button on the main form
but how do i send the count of the mrcde to the main form
It should be on the main form.

The count could be stored in a variable in the iframe and retrieved with frames["iframename"].window.countvar.
Nov 21 '07 #22

100+
P: 110
[PHP]//ini.php
for($idx=0;$idx<$count($mrcde);$idx++){
$mrcde=$_POST['mrcde'][$idx];
$mrname=$_POST['mrname'][$idx];
$qtyreqd=$_POST['qtyreqd'][$idx];
}
<form method="POST" name="ini">
<h1>Raw material</h1><table border="1">
<tr>
<thead><th>Code</th><th>Material </th><th>Units</th><th>Qty</th><th>Available Qty</th></thead></tr>
<?
$k=0;
$sqlraw="select A.*,B.* from material a,trlist b where a.code=b.code && a.packcode='$mcode'";
$queryraw=mysql_query($sqlraw);
WHILE($CONDITION){
<tr>
<td width="5"><input type="text" value="<?=$mrcde?>" name='<?="mrcde[".$k."]"?>' id='<?="mrcde[".$k."]"?>' maxlength="6" disabled readonly="y"></td>
<td colspan="2"><input type="text" value="<?=$mrname?>" name='<?="mrname[".$k."]"?>' id='<?="mrname[".$k."]"?>' maxlength="60" disabled readonly="y"></td>
<td><input type="text" value="<?=$qtyreqd?>" name='<?="qtyreqd[".$k."]"?>' id='<?="qtyreqd[".$k."]"?>' disabled readonly="y" ></td>
</tr>
}
<tr><td><input type="submit" name="save" value="Save" ></td></tr>
</table>
</form>

</body>
</html>



//main.php only iframe part
<iframe name="iframe1" src="ini.php" width="50" height="100" frameborder="1" scrolling="YES" hspace="20" vspace="10" >
</iframe><?
<tr><td><input type="button" value="Go" onclick="saveini();"></td></tr>
var iframe = frames['iframe1'];
var form = iframe1.document.forms["ini"];
for($j=0;$j<count(form.mrcde);$j++){
mrcde=$_POST['mrcde'][$j];
mrname=$_POST['mrname'][$j];
$qtyreqd=$_POST['qtyreqd'][$j];
<tr>
<td width="5"><input type="hidden" value="<?=$mrcde?>" name='<?="mrcde[".$j."]"?>' id='<?="mrcde[".$j."]"?>'></td>
<td colspan="2"><input type="hidden" value="<?=$mrname?>" name='<?="mrname[".$j."]"?>' id='<?="mrname[".$j."]"?>'></td>
<td><input type="hidden" value="<?=$qtyreqd?>" name='<?="qtyreqd[".$j."]"?>' id='<?="qtyreqd[".$j."]"?>'></td>
</tr>

}


}?>



<table>
<tr>
<td colspan="7"> <div align="center">
<input type="button" name="save" value="Save" tabindex="16" onClick="javascript:savecde();">
<input type="button" name="cancel" value="Cancel" tabindex="17" onClick="javascript:cancelcde();">
</div></td>
</tr>
</table>
<?
}
}
?>
</table>[/PHP]
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function saveini(){
  3. mrcde=document.getElementById('frame1').contentWindow.document.getElementById('mrcde[0]').value;
  4. //This is alerted shows me the value of raw code but i dont want to put i instead of 0 and i is the number of records or array length in ini.php
  5. but without submitting the ini.php  how do i get the count of array there to my main form if i get that then i can get values of all the rows and then generate table with hidden values which i will use for inserting in the database
  6.  
  7.  
  8. thanks in advance
  9.  
  10. </script>
Nov 24 '07 #23

100+
P: 110
[PHP]//ini.php

<form method="POST" name="ini">
<h1>Raw material</h1><table border="1">
<tr>
<thead><th>Code</th><th>Material </th><th>Units</th><th>Qty</th><th>Available Qty</th></thead></tr>
<?
$k=0;
$sqlraw="select A.*,B.* from material a,trlist b where a.code=b.code && a.packcode='$mcode'";
$queryraw=mysql_query($sqlraw);
WHILE($CONDITION){
<tr>
<td width="5"><input type="text" value="<?=$mrcde?>" name='<?="mrcde[".$k."]"?>' id='<?="mrcde[".$k."]"?>' maxlength="6" disabled readonly="y"></td>
<td colspan="2"><input type="text" value="<?=$mrname?>" name='<?="mrname[".$k."]"?>' id='<?="mrname[".$k."]"?>' maxlength="60" disabled readonly="y"></td>
<td><input type="text" value="<?=$qtyreqd?>" name='<?="qtyreqd[".$k."]"?>' id='<?="qtyreqd[".$k."]"?>' disabled readonly="y" ></td>
</tr>
}

//addition for getting count of rows
<input type="k" id="k" value='<?=$k?>'>

<tr><td><input type="submit" name="save" value="Save" ></td></tr>
</table>
</form>

</body>
</html>



//main.php only iframe part
<iframe name="iframe1" src="ini.php" width="50" height="100" frameborder="1" scrolling="YES" hspace="20" vspace="10" >
</iframe><?
<tr><td><input type="button" value="Go" onclick="saveini();"></td></tr>

//function saveini gives me values of the rows from the ini.php but
again now i want to create the same rows here like this n pass the value i have got in saveini to table with hidden rows main.php but here how to access that saveini p value for number of rows


<tr> <td width="5"><input type="hidden" value="<?=$mrcde?>" name='<?="mrcde[".$j."]"?>' id='<?="mrcde[".$j."]"?>'></td>
<td colspan="2"><input type="hidden" value="<?=$mrname?>" name='<?="mrname[".$j."]"?>' id='<?="mrname[".$j."]"?>'></td>
<td><input type="hidden" value="<?=$qtyreqd?>" name='<?="qtyreqd[".$j."]"?>' id='<?="qtyreqd[".$j."]"?>'></td>
</tr>

}


}?>



<table>
<tr>
<td colspan="7"> <div align="center">
<input type="button" name="save" value="Save" tabindex="16" onClick="javascript:savecde();">
<input type="button" name="cancel" value="Cancel" tabindex="17" onClick="javascript:cancelcde();">
</div></td>
</tr>
</table>
<?
}
}
?>
</table>[/PHP]
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function saveini(){
  3.       document.frames['iframe1'].document.getElementById('ini').submit();
  4.      p=document.getElementById
  5.  
  6. //how to access this p in main form while creating table with hidden rows 
  7.     ('frame1').contentWindow.document.getElementById('k').value;
  8.     document.getElementById('k').value=p;
  9.    for(i=0;i<=p;i++){
  10.               mrcde=document.getElementById             ('iframe1').contentWindow.document.getElementById('mrcde[i]').value;
  11. mrname=document.getElementById('iframe1').contentWindow.document.getElementById('mrname[i]').value;
  12. qtyreqd=document.getElementById('iframe1').contentWindow.document.getElementById('qtyreqd[i]').value;
  13. //here iget alll the values from ini.php
  14. }    
  15.  
  16.  
  17. thanks in advance
  18.  
  19. </script>
Nov 24 '07 #24

100+
P: 110
using innerhtml i have shown the table on the main form but how i post is and save in the database
Nov 26 '07 #25

acoder
Expert Mod 15k+
P: 16,027
using innerhtml i have shown the table on the main form but how i post is and save in the database
If this is part of the form, it will be posted to the action page to save to the database.
Nov 26 '07 #26

100+
P: 110
[PHP]//i tried alerting count of like this

//count($_POST['rmcde']);

//after submitting main form
//but i 'm nt getting anything in this alert although
//the form show s the table with the rmcde rmname qtyreqd
//in the main form


//but as i said i had other method to also that is passing the count of the rows //from iframe file to main page n putting it int he hidden field int he main form
//this if alert i get
//but here the prblem is i want to create table with count of rows



//main.php only iframe part
<iframe name="iframe1" src="ini.php" width="50" height="100" frameborder="1" scrolling="YES" hspace="20" vspace="10" >
</iframe><?
<tr><td><input type="button" value="Go" onclick="saveini();"></td></tr>


<input type="k" id="k" value=''> //gives me number of rows from the iframe file


//but the k value is alerted properly after submitting main form since i have passed it to input box
//is there anyways i can create the table using k value with the values assigned from down saveini function down here









<table>
<tr>
<td colspan="7"> <div align="center">
<input type="button" name="save" value="Save" tabindex="16" onClick="javascript:savecde();">
<input type="button" name="cancel" value="Cancel" tabindex="17" onClick="javascript:cancelcde();">
</div></td>
</tr>
</table>
<?
}
}
?>
</table>[/PHP]


Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function saveini(){
  3.       document.frames['iframe1'].document.getElementById('ini').submit();
  4.      p=document.getElementById
  5.     ('frame1').contentWindow.document.getElementById('  k').value;
  6.     document.getElementById('k').value=p;
  7.    for(i=0;i<=p;i++){
  8.        mrcde=document.getElementById             ('iframe1').contentWindow.document.getElementById(  'mrcde[i]').value;
  9.     mrname=document.getElementById('iframe1').contentW  indow.document.getElementById('mrname[i]').value;
  10.     qtyreqd=document.getElementById('iframe1').content  Window.document.getElementById('qtyreqd[i]').value;
  11.     //here iget alll the values from ini.php
  12. }   
  13.  
  14. </script>
help
Nov 26 '07 #27

acoder
Expert Mod 15k+
P: 16,027
OK, can you show me the client-side generated code for the iframe (not PHP, just simple HTML).
Nov 27 '07 #28

Post your reply

Sign in to post your reply or Sign up for a free account.