Jump to content

reading value of html elements


shane07

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/85491-reading-value-of-html-elements/
Share on other sites

<?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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.