shane07 Posted January 11, 2008 Share Posted January 11, 2008 Hello Is it possible to read the value of the html element like hidden field and store in the server side variable without reloading the page? I have a hidden field. I have to change the value of that field with the returned value of confirm dialog box using javascript which I did. But I have to store the value of the field in a php variable. Or is there any way to read the value returned by the confirm dialog box using PHP? Thanx Quote Link to comment https://forums.phpfreaks.com/topic/85491-reading-value-of-html-elements/ Share on other sites More sharing options...
Lumio Posted January 11, 2008 Share Posted January 11, 2008 <?php $value = 0; if (!isset($_GET['value']) || !is_numeric($_GET['value'])) $value = intval($_GET['value']); ?><input type="hidden" name="foo" value="<?php echo $value; ?>" /> Do you mean that? Quote Link to comment https://forums.phpfreaks.com/topic/85491-reading-value-of-html-elements/#findComment-436289 Share on other sites More sharing options...
Ken2k7 Posted January 11, 2008 Share Posted January 11, 2008 Lumio's method work, but you have to use JavaScript to redirect the user with the URL that contains the return value. Quote Link to comment https://forums.phpfreaks.com/topic/85491-reading-value-of-html-elements/#findComment-436291 Share on other sites More sharing options...
shane07 Posted January 11, 2008 Author Share Posted January 11, 2008 <?php $value = 0; if (!isset($_GET['value']) || !is_numeric($_GET['value'])) $value = intval($_GET['value']); ?><input type="hidden" name="foo" value="<?php echo $value; ?>" /> Do mean that? I mean is it possible without reloading the page? I need exactly the reverese process i.e. The value of the hidden field should be assigned to php variable which changes dynamically within a loop for($i=1;$i<$num;$i++) { $destdir="../images/categories"; $files1=scandir($destdir); //echo $files[$i]." "; $flag=0; foreach($files1 as $file) { if($file==$files[$i]&&$file!="Thumbs.db") { //echo $i." ".$file." ".$files[$i]; if($files[$i]!="..") $flag=1; } } if($flag==1) { ?> <script language="javascript"> var ch=confirm("<?php echo $files[$i];?> already exists"); if(ch==false) document.frm.hdn.value="false"; else if(ch==true) document.frm.hdn.value="true"; </script> <?php } else {if($files[$i]!="Thumbs.db") { if($files[$i]!="..") {copy($dir."/".$files[$i],"../images/categories/".$files[$i]); unlink($dir."/".$files[$i]); } } } } Here is the code which I am working on I want to copy the file only when it does not exist So I have to something befor the copy function Quote Link to comment https://forums.phpfreaks.com/topic/85491-reading-value-of-html-elements/#findComment-436293 Share on other sites More sharing options...
shane07 Posted January 11, 2008 Author Share Posted January 11, 2008 Is there any way to run php scripts if user clicks on "yes" button of confirm dialog box otherwise do not run the php scripts? I tried <script language="javascript"> var ch=confirm("<?php echo $file;?> already exists. Do you want to replace it?"); if(ch==true) { <?php $copied=@copy($dir."/".$file,"../images/categories/".$file); if($copied==true) $count_files++; ?> } But it didn't work. Instead the php scripts run despite of checking the condition. Any advice will be appreciable Thanx Quote Link to comment https://forums.phpfreaks.com/topic/85491-reading-value-of-html-elements/#findComment-436353 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.