assaf
assaf

Reputation: 37

sending values from php to javascript and from javascript to php

So I have this input:

<input type="text" id="url" onchange="update(this.value)">

what I want to do is when this input change, the value will be taken to another input but before that I need to make a php function on it.

so I thought on something like this:

function update(url)
{
     var src = <?php echo json_encode(getUrl(*****url*****)) ?>;
     document.getElementById("src").value = src;
}

but since the url variable is in js I cant send it in php.

any suggestions?

Upvotes: 0

Views: 89

Answers (2)

Mina
Mina

Reputation: 1516

As it was pointed out already you have to use Ajax to communicate with your PHP script. Have a look at this http://fiddle.jshell.net/Qvqha/

Upvotes: 1

Ronak Patel
Ronak Patel

Reputation: 390

If you want to call PHP function. Then that function should be in PHP code.

If you want to pass text box variable to another place on change event, then you need to use ajax call.

Check this link:

PHP: get the value of TEXTBOX then pass it to a VARIABLE

Upvotes: 0

Related Questions