Jump to content

variables with javascript


jwk811

Recommended Posts

could i just do something in a script with javascript and make a variable called either true or false and then use it in my php code? like say i have a form and there is two radio button options and once someone clicks one i have javascript check which one they clicked and if they clicked the first one javascript would make a variable called true and falses for the other option. then i can take that variable and use it to display a different set of options if its true and another set if its false. am i on the right track? can this work? how can i do this? and am i making any sense? lol
Link to comment
https://forums.phpfreaks.com/topic/26268-variables-with-javascript/
Share on other sites

Well you can't actually name the variable true or false, but if you have two radio buttons with the same name but unique ids, say true and false, you can just assign it like

[code]var isTrue = document.getElementById("true").checked;[/code]

you could also validate it easily

[code]var isFalse = document.getElementById("false").checked;
if (!isTrue && !isFalse){
alert("Please choose true or false.");
return false;
}[/code]

( document.myFormName.myRadioName[0] and document.myFormName.myRadioName[1] would probably actually be compatible with more browsers, but it's just an example. )

Using it in the PHP coding is exactly the type of thing I need to learn, so I can't be any help there.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.