Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
HTML
<html>
<head>
<meta name="datetime" content="Date09-09-2011-Time10-07-16">
<script type="text/javascript" language="javascript">
function GetValue()
{
var arrayOfAnchors = document.all.tags("meta");
var value1 = arrayOfAnchors[0].content;
document.getElementById('final').value= value1;
}
</script>
</head>

<body>
<form method="post" action="NewPhpWriteFile.php">
<input type="hidden" id = "final" name="sometext" value= "Hello Sir" >
<input type="submit" name = "submit" id="btnClick" value="Click Me" onclick="GetValue()"/>
</form>
</body>
</html>


This is the NewPhpWriteFile.php

PHP
if (isset($_POST['sometext']))
{
	$myFile = "testFile.txt";
	$thetext=$_POST['sometext'];
	writemyfile($myFile,$thetext,"w");
	parent.focus();
} else
{
	$thetext="Enter text here";
}
?>


When i execute the file, and click the button "Click Me", only the string "Hello Sir" is passed to the new file "NewPhpWriteFile", the value of id "final" is not getting updated before it is passed to the new php file.

Can some one suggest me whats going wrong? Is there any other way to do this?
Posted
Updated 19-Oct-11 19:02pm
v2
Comments
Sergey Alexandrovich Kryukov 20-Oct-11 0:44am    
There is no PHP here. How it's relevant?
--SA
amarasat 20-Oct-11 0:59am    
Yah you are right, in this code there is no php code, but i am calling a PHP file with a POST action and passing value from variable "sometext", i will improve the question by adding the .php file code also

1 solution

this is my answer:
- change btonClick type from "Submit" to "Button".
HTML
<input type="button" name="submit" id="btnClick" value="Click Me"  önclick="GetValue()" />

- in function getValue():
JavaScript
function GetValue(){
    var arrayOfAnchors = document.all.tags("meta");
    var value1 = arrayOfAnchors[0].content;
    document.getElementById('final').value= value1;
    document.form[0].submit();
}
 
Share this answer
 
v2
Comments
amarasat 20-Oct-11 9:58am    
Thanks a lot its working, in the way you suggested, if first threw an error documnt.form.0 is null, but after a while it worked, sounds strange to me. One more issue is, this loads up the new page "NewPhpWriteFile.php" and says, "Internet Explorer cannot display the page", can you help me with any one of this. 1.) To let the focus not shift to the "NewPhpWriteFile.php" in the browser.
((or))

2.) How to load another simple html page from the "NewPhpWriteFile.php" which says "Waiting for the report to be generated".
((or))

3.) To return the focus back to the Test.html page(parent) which is calling the "NewPhpWriteFile.php" in the above code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900