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
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.
Link to comment
Share on other sites

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.