Jump to content

Recommended Posts

I am trying to learn php and js. Here I am trying to put a value in php varible from javascript alert message input box but failed.
here what I have done so far,

// <?PHP and other variable is here....
$number='number'; 

<script>
			function number{
				
				if (fail == "") {
					number = prompt('Please enter Phone Number')
					if (number == "" || number == null) { 
						alert(' You have not specified the Phone Number. Please try again.'); 
						
						return false;
					}
					else {
						
						document.getElementById("number").value;
						
						return true;
					}
				}
				else { alert(fail); return false; }
			}
		</script>

So, actually how I can store the value from js alert to php varible? help me. Thanks for your valuable time and opinion.

The only way to get a value from JS to your PHP is to send a request from the JS to your server. This could either be through a form submission or an AJAX request

 

PHP is run on the server, whereas JS is run on the client, essentially 2 completely different places that each have no idea about the other.

Edited by denno020
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.