Page 1 of 1

Passing data back to .html file

Posted: Wed Dec 06, 2006 1:49 pm
by wep
I have a site already written with html. Now that I've learned some php I want to open a data file with php code, read in the text and pass it back to the calling website to display it. I've been able to easily send data from forms, text boxes etc. to a php program but not the other way round. Any help?

Thanks!
Bill

Posted: Wed Dec 06, 2006 2:02 pm
by ok
You need to use JS for this purpose. Some code I wrote in quickly:

Code: Select all

<script type="text/javascript">
var temp = location.search;

var idx2_data1;
var idx2_data2;
if(temp)
{
   var idx1_data1 = temp.indexOf("?data1=");
   var idx1_data2 = temp.indexOf("&data2=");

   if ((idx1_data2 >= 0)&&(idx1_data1 >= 0))
   {
        //The size of idx1_data1
	idx1_data1 += 7;
        //The size of idx1_data2
	idx1_data2 += 7;

	var idx2_data2 = temp.indexOf("&", idx1_data2);
	var idx2_data1 = temp.indexOf("&", idx1_data1);
 	if (idx2_data2 > 0) { data2 = temp.substring(idx1_data2, idx2_data2); } else { data2 = temp.substring(idx1_data2); }  
	if (idx2_data1 > 0) { data1 = temp.substring(idx1_data1, idx2_data1); } else { data1 = temp.substring(idx1_data1); }  
   }
}
document.writeln('<font color="#cc0000"><b>Data1:</b></font> '+data1);
document.writeln('<font color="#cc0000"><b>Data2:</b></font> '+data2);
</script>
You can find tutorial about JS in: http://www.w3schools.com/js/default.asp

Re: Passing data back to .html file

Posted: Wed Dec 06, 2006 3:32 pm
by RobertGonzalez
wep wrote:I have a site already written with html. Now that I've learned some php I want to open a data file with php code, read in the text and pass it back to the calling website to display it. I've been able to easily send data from forms, text boxes etc. to a php program but not the other way round. Any help?

Thanks!
Bill
This does not require the use of Javascript at all. Use the PHP filesystem functions mixed with what you already know about displaying data to the screen.

Re: Passing data back to .html file

Posted: Wed Dec 06, 2006 3:34 pm
by John Cartwright
wep wrote:I have a site already written with html. Now that I've learned some php I want to open a data file with php code, read in the text and pass it back to the calling website to display it. I've been able to easily send data from forms, text boxes etc. to a php program but not the other way round. Any help?

Thanks!
Bill
Why not have php process both pages?

Re: Passing data back to .html file

Posted: Wed Dec 06, 2006 5:46 pm
by wep
Jcart wrote:
wep wrote:I have a site already written with html. Now that I've learned some php I want to open a data file with php code, read in the text and pass it back to the calling website to display it. I've been able to easily send data from forms, text boxes etc. to a php program but not the other way round. Any help?

Thanks!
Bill
Why not have php process both pages?
I have done that and all works great. I just thought there should be a way to do it as described and if there is a way (without JS) then I should learn about it.

Thanks a lot for responding.

Bill

Posted: Wed Dec 06, 2006 5:49 pm
by feyd
Static HTML can't pull jack if it doesn't have Javascript to do it as there aren't any native controls to pull in information from anywhere. Sticking to PHP works perfectly fine in this, so don't sweat it. :)