shiloh2 Posted July 2, 2009 Share Posted July 2, 2009 Hi, i just want to ask for any help about my problem.. Im using javascript to get the value of my dropdown. using the onchange Event. Here is my Code: my dropdown selected is "Third Grading" $drop = '<script language="javascript">document.write(document.getElementById("grading").value)</script>'; if ($drop == "Third Grading") { echo "ok"; }else{ echo "no"; } i used var_dump($drop) and var_dump("Third Grading") .. this is the result string(95) "Third Grading" string(13) "Third Grading" end one echo "no" resulting the else in if statement.. can someone help me why it results to "no".. Quote Link to comment https://forums.phpfreaks.com/topic/164460-help-php-operator-clarification/ Share on other sites More sharing options...
Philip Posted July 2, 2009 Share Posted July 2, 2009 Well, technically $drop is <script language="javascript">document.write(document.getElementById("grading").value)</script> Since PHP is server side, that would not parse until the user views it - at which point PHP has already done its job Quote Link to comment https://forums.phpfreaks.com/topic/164460-help-php-operator-clarification/#findComment-867515 Share on other sites More sharing options...
pkedpker Posted July 2, 2009 Share Posted July 2, 2009 you have to evalulate the javascript function PHP just uses that whole javascript as a text.. its not code in PHP Quote Link to comment https://forums.phpfreaks.com/topic/164460-help-php-operator-clarification/#findComment-867517 Share on other sites More sharing options...
shiloh2 Posted July 2, 2009 Author Share Posted July 2, 2009 @kingphilip Yes, it is <script language="javascript">document.write(document.getElementById("grading").value)</script> .. but when i var_dump that, it will return to "Third Grading" .. so i decided to match with a string.. but fails. any ideas? @pkedpker. how to encode it to php? .. Quote Link to comment https://forums.phpfreaks.com/topic/164460-help-php-operator-clarification/#findComment-867518 Share on other sites More sharing options...
Philip Posted July 2, 2009 Share Posted July 2, 2009 Do you see the difference between the two: var_dump($drop) => string(95) "Third Grading" var_dump("Third Grading") => string(13) "Third Grading" Quote Link to comment https://forums.phpfreaks.com/topic/164460-help-php-operator-clarification/#findComment-867520 Share on other sites More sharing options...
pkedpker Posted July 2, 2009 Share Posted July 2, 2009 yah like what King pointed out the first one is Third Grading but its a string of 95 characters but just Third Grading is 13 characters U'd have to use ajax to do what you are trying to do is simple form get/post METHOD or why not code it completely in javascript i'm sure there is a ECHO command in javascript. Quote Link to comment https://forums.phpfreaks.com/topic/164460-help-php-operator-clarification/#findComment-867523 Share on other sites More sharing options...
shiloh2 Posted July 2, 2009 Author Share Posted July 2, 2009 yes i saw that.. they dont have the same string length.. but what im after is the string value itself. do you have some idea on how to match the two?? thanks in advance.. Quote Link to comment https://forums.phpfreaks.com/topic/164460-help-php-operator-clarification/#findComment-867524 Share on other sites More sharing options...
pkedpker Posted July 2, 2009 Share Posted July 2, 2009 I have no idea what you are trying to do but your problem is extremely easy you should of just posted more code.. I think what you are attempting to do is when a user picks a dropdown selection.. it would send something to PHP to check if its Third Grading then return ok or no.. I don't think just selecting something in a dropdown will actually send anything unless you mess around with javascript like on dropdown change onClick=javaScript:submit.form(); or something like that.. which will then send it to PHP and it will all work fine. Quote Link to comment https://forums.phpfreaks.com/topic/164460-help-php-operator-clarification/#findComment-867525 Share on other sites More sharing options...
shiloh2 Posted July 2, 2009 Author Share Posted July 2, 2009 im not good at javascript. that's why im here asking for ideas .. Quote Link to comment https://forums.phpfreaks.com/topic/164460-help-php-operator-clarification/#findComment-867527 Share on other sites More sharing options...
pkedpker Posted July 2, 2009 Share Posted July 2, 2009 work of this I'm not good at javascript either.. just started it today but its not hard to pick it up.. I mean i did in a day.. <?php //cOLOrZ <form name="myform" action="grading.php" method="POST"> <SELECT> <OPTION value="Third Grading" selected onClick="submitform();">3rd</option> <OPTION value="Second Grading" onClick="submitform();">2nd</option> <OPTION value="First Grading" onClick="submitform();">1st</option> </select></form> <SCRIPT language="JavaScript"> function submitform() { document.myform.submit(); } </SCRIPT> ?> Note that above is not PHP file its just a plain html file.. BUT IT calls a PHP file.. with a $ans = $_POST['Third Grading']; Quote Link to comment https://forums.phpfreaks.com/topic/164460-help-php-operator-clarification/#findComment-867530 Share on other sites More sharing options...
shiloh2 Posted July 2, 2009 Author Share Posted July 2, 2009 OK, i think i can re plan my logic here. and i can apply your idea. thank's for helping. i will repost if what will be the outcome. thanks again Quote Link to comment https://forums.phpfreaks.com/topic/164460-help-php-operator-clarification/#findComment-867559 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.