Rakeshhit Posted September 24, 2014 Share Posted September 24, 2014 (edited) 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 September 24, 2014 by Rakeshhit Quote Link to comment Share on other sites More sharing options...
requinix Posted September 24, 2014 Share Posted September 24, 2014 You can't mix and match Javascript and PHP like that. For now use a regular and get it working. Then learn about AJAX and you'll be able to do this the way you want. Quote Link to comment Share on other sites More sharing options...
Rakeshhit Posted September 24, 2014 Author Share Posted September 24, 2014 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. Quote Link to comment Share on other sites More sharing options...
requinix Posted September 24, 2014 Share Posted September 24, 2014 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
× 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.