program php and alert javascript on form html -



program php and alert javascript on form html -

i have problem simple programme in php include alert javascript. code:

<?php function iva(){ $country='it'; $vatnum=$_post['n']; $a="work"; $b="notwork"; $url='http://isvat.appspot.com/'.$country.'/'.$vatnum.'/'; $response = file_get_contents($url); //global $a, $b; if( $response == 'true' ){ echo $a; } if ($response != 'true'){ echo $b; } } ?> <script> function ivaz(){ alert("<?php iva() ?>"); } </script> <form method="post"> <input name="n" type="textarea" > <input onclick="ivaz();" value="validate" type="submit"> </input> </form>

my programme take value input text box , pass value php script homecoming true or false in javascript alert. programme work, homecoming previous value passed in input box. can help me solve it?

thanks guys.

no, doesn't work way. if want phone call php function javascript without page refreshing, need xmlhttprequest.

example:

<?php // php process when called xmlhttprequest if($_server['request_method'] == 'post') { $vatnum = $_post['n']; $country='it'; $a = "work"; $b = "notwork"; $url = 'http://isvat.appspot.com/'.$country.'/'.$vatnum.'/'; $response = file_get_contents($url); //global $a, $b; if( $response == 'true' ){ echo $a; } else { echo $b; } exit; } ?> <form method="post" id="form1"> <input name="n" type="text" id="n" /> <input value="validate" type="submit"> </form> <script type="text/javascript"> // when form submitted document.getelementbyid('form1').addeventlistener('submit', function(e){ e.preventdefault(); var n = document.getelementbyid('n').value; // textbox value var xmlhttp = new xmlhttprequest(); var params = 'n=' + n; var php_url = document.url; xmlhttp.open('post', php_url, true); xmlhttp.setrequestheader("content-type", "application/x-www-form-urlencoded"); xmlhttp.onreadystatechange = function() { if (xmlhttp.readystate == 4 && xmlhttp.status == 200) { var response = xmlhttp.responsetext; alert(response); // alert server response } } xmlhttp.send(params); }); </script>

javascript php html web

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -