Jump to content

Pass value to PHP variable


Rakeshhit

Recommended Posts

I have researched all over forums from past day. Not getting correct solution. I have 2 textboxes and a button. First box is to enter value and i will click button, i need to get the value.

 

Here is the code, that works without input box 1

 

In this code i want to modify my web address, at the end after ky= i want add my first textbox value, then click event and output in second textbox, let me know where i messed.

 

<script type="text/javascript">
function Assign() 
{
<?php
$html = file_get_contents("http://geoportaal.maaamet.ee/url/xgis-ky.php?ky=79401:006:0812" );
preg_match_all('(<li.*?>.*?</li>)', $html, $matches);
$one=$matches[0][0];


?>
document.getElementById("OutputField").value = "<?=$one?>";
}
</script>




<input id="InputField" type="text" style="width:200px"/>
<input type="submit" value="Assign Value" onclick="Assign()"/>
<input id="OutputField" type="text" style="width:200px"/>
Edited by Rakeshhit
Link to comment
Share on other sites

You can't mix and match Javascript and PHP like that.

 

For now use a regular <form> and get it working. Then learn about AJAX and you'll be able to do this the way you want.

I tried something like this :

<?php
$html = file_get_contents("http://geoportaal.maaamet.ee/url/xgis-ky.php?ky=79401:006:0812");
preg_match_all('(<li.*?>.*?</li>)', $html, $matches);
$one=$matches[0][0];
?>

<script type="text/javascript">
function Assign() {
    document.getElementById("OutputField").value = "<?=$one?>";
}
</script>
<input id="inputfield" type="text" style="width:200px"/>
<input id="OutputField" type="text" style="width:200px"/>
<input type="button" value="Assign Value" onclick="Assign()"/>

Code is working, but i need to add the Inputfield value at the end of webaddress (After ky=) that part i am not sure.

Link to comment
Share on other sites

Right. Same question, same answer: use a regular

to send the inputfield value to PHP, then PHP can figure out the value of $one and put it in outputfield's value directly.

And then when you have that working you can learn about AJAX, which lets you send stuff from Javascript directly to PHP, read the response directly, and do whatever it wants, without having to use a form that will (re)load the page.

Link to comment
Share on other sites

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.