Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.