3 Replies - 441 Views - Last Post: 28 December 2010 - 10:11 PM

#1 CodeVillain  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 143
  • Joined: 10-July 10

PHP/JavaScript issues

Posted 28 December 2010 - 07:42 PM

Okay, so I can't figure this one out for the live of me.

if($row['country'] === "United States" && $row['zip'] === NULL){
echo "<form name='s3804form' action='petitions/s3804.php' method='post'><div class='sbutton' onclick='document.s3804form.submit()'>Sign it</div></form>";
} else {

echo "<form name='s3804form' action='petitions/s3804.php' method='post'><div class='sbutton' onclick='document.s3804form.submit()'>Sign it</div></form>";
		
}


For some reason the first button <div class='sbutton' onclick='document.s3804form.submit()'> isn't submitting the form, but the second one submits it without any issues, despite it being the exact same code that's being echoed out. Does anyone have a clue what's going on here?

This post has been edited by CodeVillain: 28 December 2010 - 08:08 PM


Is This A Good Question/Topic? 0
  • +

Replies To: PHP/JavaScript issues

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4354
  • View blog
  • Posts: 12,160
  • Joined: 18-April 07

Re: PHP/JavaScript issues

Posted 28 December 2010 - 09:27 PM

You are going to have to show us more. That is not enough info to know why one would be working and the other is not. It is like saying why is "hello world" working but not "hello world"? You can't say without seeing the context it is in. Also check out how you are testing $row['zip']. Very rarely would you be checking for null... you might want to use isset() or empty() to check if it is set or empty. Could this possibly be always executing the else? Tell us how you are testing this.

Thanks for helping us help you.

:)

This post has been edited by Martyr2: 28 December 2010 - 09:29 PM

Was This Post Helpful? 0
  • +
  • -

#3 CodeVillain  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 143
  • Joined: 10-July 10

Re: PHP/JavaScript issues

Posted 28 December 2010 - 09:55 PM

View PostMartyr2, on 28 December 2010 - 07:27 PM, said:

You are going to have to show us more. That is not enough info to know why one would be working and the other is not. It is like saying why is "hello world" working but not "hello world"? You can't say without seeing the context it is in. Also check out how you are testing $row['zip']. Very rarely would you be checking for null... you might want to use isset() or empty() to check if it is set or empty. Could this possibly be always executing the else? Tell us how you are testing this.

Thanks for helping us help you.

:)


Well that seemed to be the only significant part of my code. I pulled $row['zip'] from my database and tested it with null values and not and it would return the code properly either way. The point is that it's obviously echoing out the code or nothing would be showing up, everything appears to be on there correctly it's simply not submitting. My question was in hopes someone has experienced a similar problem with if else statements. I'd rather not send all my code because I'm doing it using facebook's php sdk which means I'd have to copy and paste very large chunks of code just to show where everything is coming from, and comb through it and remove tons of info.

Thanks anyway.
Was This Post Helpful? 0
  • +
  • -

#4 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4354
  • View blog
  • Posts: 12,160
  • Joined: 18-April 07

Re: PHP/JavaScript issues

Posted 28 December 2010 - 10:11 PM

Well if it is printing an output in either scenario, then the problem has nothing to do with the code you are showing right? If both are identical and despite whether the first or the second shows (the end result is the same line echoed) then your problem is not in this if statement. Which is why we are not asking you to send all your code, but perhaps the function this is written in.

Do you have a URL we can access with this code on it?

Edit:

If you are not getting what I am saying, assume the following...

if (a == 1) {
  print b
}
else {
  print b
}



What is the result? "print b" despite which branch it executed. This means that if you have a problem, it is not with this if statement. The problem is elsewhere.

This post has been edited by Martyr2: 28 December 2010 - 10:13 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1