Login | Register | FAQ
Anonymous

Javascript + PHP Question

+ Post a reply

7 posts Page 1 of 1


Javascript + PHP Question

by soccerwebsitemaker » Mon Jun 04, 2012 8:28 pm

Is it possible to do something like this:



<input type="radio" name="radiobutton" onclick="<?php code?>" />

In a sense, putting PHP code into a JavaScript function?

If not possible to do it in that way, is there another way to do it?

You see, what I'm trying to do:

I have radio buttons that I "echo" because they need to be enabled or disabled depending on data in a database. That part works. But how do I make this into a form?

Is there anyway to send radio button data when the radio buttons are created like this:

Code: Select all
while($row3 = mysql_fetch_array($rs3)){

$blueBG = $row3["BlueBG"];

$yellowBG = $row3["YellowBG"];

$greenBG = $row3["GreenBG"];

$redBG = $row3["RedBG"];

$purpleBG = $row3["PurpleBG"];

$blackBG = $row3["BlackBG"];

}

if ($blueBG == 'yes')

{

echo '

<input type="radio" value="Blue" name="bgselect" id="bluebgradio" /><label id="bluebgradiol">Blue</label>';

}

else

{

if ($_SESSION["Login"] != "YES")

{

echo '';

}

else

{

echo '<input type="radio" value="Blue" name="bgselect" disabled="disabled" id="bluebgradio" /><label id="bluebgradiol">Blue</label>';

}

}

if ($yellowBG == 'yes')

{

echo '<input type="radio" value="Yellow" name="bgselect" id="yellowbgradio" /><label id="yellowbgradiol">Yellow</label>';

}

else

{

if ($_SESSION["Login"] != "YES")

{

echo '';

}

else

{

echo '<input type="radio" value="Yellow" name="bgselect" disabled="disabled" id="yellowbgradio" /><label id="yellowbgradiol">Yellow</label>';

}

}

if ($greenBG == 'yes')

{

echo '<input type="radio" value="Green" name="bgselect" id="greenbgradio" /><label id="greenbgradiol">Green</label>';

}

else

{

if ($_SESSION["Login"] != "YES")

{

echo '';

}

else

{

echo '<input type="radio" value="Green" name="bgselect" disabled="disabled" id="greenbgradio" /><label id="greenbgradiol">Green</label>';

}

}

if ($redBG == 'yes')

{

echo '<input type="radio" value="Red" name="bgselect" id="redbgradio" /><label id="redbgradiol">Red</label>';

}

else

{

if ($_SESSION["Login"] != "YES")

{

echo '';

}

else

{

echo '<input type="radio" value="Red" name="bgselect" disabled="disabled" id="redbgradio" /><label id="redbgradiol">Red</label>';

}

}

if ($purpleBG == 'yes')

{

echo '<input type="radio" value="Purple" name="bgselect" id="purplebgradio" /><label id="purplebgradiol">Purple</label>';

}

else

{

if ($_SESSION["Login"] != "YES")

{

echo '';

}

else

{

echo '<input type="radio" value="Purple" name="bgselect" disabled="disabled" id="purplebgradio" /><label id="purplebgradiol">Purple</label>';

}

}

if ($blackBG == 'yes')

{

echo '<input type="radio" value="Black" name="bgselect" id="blackbgradio" /><label id="blackbgradiol">Black</label>';

}

else

{

if ($_SESSION["Login"] != "YES")

{

echo '';

}

else

{

echo '<input type="radio" value="Black" name="bgselect" disabled="disabled" id="blackbgradio" /><label id="blackbgradiol">Black</label>';

}

}


You could also see this firsthand by going to my site: http://www.coinawards.net63.net/

make an account

login

hover over 'profile'

2nd choice is 'spruce it up' and there should be radio buttons there

(they should all be disabled because you are using a non-admin account, in which these have not been 'bought' yet(more on that later) so only admins can have them for free for testing purposes, but disabled buttons doesn't matter, right?





Simply, what I'm trying to do is make a form surrounding all these radio buttons so that the user's choices and preferences could be submitted to the server, but I've tried several ways, it does not work.


I'm asking about JavaScript onclick because I could do this:

onclick="submittoserver"

If that's possible: I'd like to know



Any help would be greatly appreciated...
User avatar

soccerwebsitemaker

  • Posts: 139
  • Joined: Sat Dec 31, 2011 6:25 pm
--
Coins. Profile. Games. Chat. Fun.

CoinAwards.

Check it out at http://www.coinawards.net63.net/

Re: Javascript + PHP Question

by XainPro » Tue Jun 05, 2012 12:17 pm

well you code is pretty messed up but yah i thing i should tell you its legal and i use this kind of forms often
<input type="radio" name="radiobutton" onclick="<?php code?>" />
its ok to do things like that but you can use it for echo purpose only you can not execute the php code onclick onclick you have to call a java script function and that function will submit the form and after the form submission the page will save the radio value.
User avatar

XainPro

  • Posts: 3547
  • Joined: Fri Feb 17, 2012 8:10 pm

Re: Javascript + PHP Question

by soccerwebsitemaker » Tue Jun 05, 2012 3:04 pm

Your reply gave me an idea: but I have another question...

Do I have to put something in a form to be able to read its value using $_POST[""};?

(e.g. if the radio button is not in a form, can I still retrieve its value with $_POST?)

If not, is there a way to submit a form without page reload???

Thank you
User avatar

soccerwebsitemaker

  • Posts: 139
  • Joined: Sat Dec 31, 2011 6:25 pm
--
Coins. Profile. Games. Chat. Fun.

CoinAwards.

Check it out at http://www.coinawards.net63.net/

Re: Javascript + PHP Question

by XainPro » Wed Jun 06, 2012 1:34 am

All you your questions answer is AJAX.
You will think now what the heck AJAX is AJAX is Asynchronous JavaScript and XML.
you can save and retrieve any value without page reloading.
for learning of AJAX you can follow there lessons
http://www.w3schools.com/ajax/default.asp
User avatar

XainPro

  • Posts: 3547
  • Joined: Fri Feb 17, 2012 8:10 pm

Re: Javascript + PHP Question

by soccerwebsitemaker » Wed Jun 06, 2012 1:44 am

Hey, wow... we never seem to be online at the same time.

Anyway, you're saying that AJAX can send my data to a database without page reload? it can communicate with PHP server side stuff?

If so, then that's great.
User avatar

soccerwebsitemaker

  • Posts: 139
  • Joined: Sat Dec 31, 2011 6:25 pm
--
Coins. Profile. Games. Chat. Fun.

CoinAwards.

Check it out at http://www.coinawards.net63.net/

Re: Javascript + PHP Question

by XainPro » Wed Jun 06, 2012 2:40 am

yah today i just getup early in the morning so i decide to check emails :) and i come to forum as well
and yah I am saying AJAX can send my data to a database without page reload
it can communicate with PHP server side stuff.
That's right :)
User avatar

XainPro

  • Posts: 3547
  • Joined: Fri Feb 17, 2012 8:10 pm

Re: Javascript + PHP Question

by soccerwebsitemaker » Wed Jun 06, 2012 10:44 am

So the most recent post of mine( not this one) it was early morning for you?

Late evening for me.

940PM for me

Well, thank you for that advice.

I'll look into AJAX and see what I can do.
User avatar

soccerwebsitemaker

  • Posts: 139
  • Joined: Sat Dec 31, 2011 6:25 pm
--
Coins. Profile. Games. Chat. Fun.

CoinAwards.

Check it out at http://www.coinawards.net63.net/


+ Post a reply

Page 1 of 1

?>