Jump to content

Recommended Posts

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".. 

 

Link to comment
https://forums.phpfreaks.com/topic/164460-help-php-operator-clarification/
Share on other sites

@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?  ..

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.

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.  :D

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'];

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.