0

I made some javascript code to view the text inside input text. When I click on the submit with this code:

alert("The field contains the text: " + frm.find.value)

This works, so I want use this part from javascript in php "frm.find.value"

for example: I'll write the wrong code as i used it:

$j='<script>+ frm.find.value<script/>';
$code = mysql_query("SELECT * FROM s_output WHERE name='$j'");
while($rowc = mysql_fetch_array($code))
  {
  $code=$rowc['code'];
  }
echo $code;

This code for view code number using the name from database. i can use it with only php, but in my example I cant because I have an error with charset UTF-8, SO i just need use the code or numbers.

Thanks

Kieran
  • 2,554
  • 3
  • 26
  • 38
rixlinux
  • 199
  • 1
  • 3
  • 12
  • 2
    I'm not at all sure what the question is, but I'm guessing this is a duplicate of http://stackoverflow.com/questions/2338942/access-a-javascript-variable-from-php – JJJ Jan 13 '12 at 17:43
  • I presume you are running the PHP after you submitted the form? In which case, you'll have to use `$_GET` or `$_POST` - PHP knows nothing of javascript, especially on a page that no longer exists, because you submitted the form on it... – DaveRandom Jan 13 '12 at 17:43
  • I'm not sure what your question is, but javascript is client-side while php is server-side, so you will have to post the data from your javascript to a php file. – Cyclonecode Jan 13 '12 at 17:43
  • It can't work this way. Use AJAX. – Michael Sazonov Jan 13 '12 at 17:44
  • PHP runs on the server, generates some HTML, then sends it to the browser, where it's parsed. PHP cannot access JavaScript variables. You're gonna need to use AJAX (or add the value to a form and submit it). – gen_Eric Jan 13 '12 at 17:48
  • my problem with jquery mobile so the charset in database is UTF-8 and in insert the data with charset=windows-1256. when i put any one of them i cant view the arabic data but i can only view an english data. – rixlinux Jan 13 '12 at 18:00

1 Answers1

0

you have right idea... use an ajax call to your php page where the php page echoes the result. Here is a not-so-elegant example to demonstrate, http://www.w3schools.com/php/php_ajax_database.asp

Robert
  • 204
  • 1
  • 10