Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP Sticky For to pass variable to JQuery

Posted on 2014-01-28
4
Medium Priority
?
414 Views
Last Modified: 2014-02-03
I want to pass a php form sticky entry to Jquery upon page refresh.

PHP Code:
	function choose_registration_type() {
		echo '  <h4>I Would Like To:</h4><br />
				<input type="radio" name="team_join" id="create_new_team" value="Create New Team" />Create New Team<br />
				<input type="radio" name="team_join" id="join_existing_team" value="Join Existing Team"'; if(isset($_POST['team_join']) && $_POST['team_join'] == "Join Existing Team") {echo'checked';} echo'/>Join Existing Team<br />
				<input type="radio" name="team_join" id="join_individually" value="Join Individually" />Join Individually';
	}

Open in new window

So if the form fails, the radio button is still chosen. However, this is within a div that is shown/hidden by JQuery  with a $(document).ready(function()

So since this radio button is already "Checked" I want the div to automatically show.
But, the following does not work:
$(document).ready(function() {
$('input[type="radio"]').checked(function() {
		if ($(this).attr("value") == "Join Existing Team") {
		$("#join_group").show('fast');
		}
	});
});

Open in new window

0
Comment
Question by:rgranlund
4 Comments
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 39816585
What about :
$(document).ready(function() {
        var checked = $('input[type="radio"]:checked');
        var at_least_one_is_checked = checked.length > 0;
        var is_Join_Existing_Team = checked.attr("value") == "Join Existing Team";
	if( checked.length>0 && is_Join_Existing_Team ) {
		$("#join_group").show('fast');
	};
});

Open in new window

0
 
LVL 5

Expert Comment

by:Alex Ene
ID: 39816659
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39817630
...if the form fails, the radio button is still chosen
What do you mean by if the form fails?
0
 
LVL 7

Author Closing Comment

by:rgranlund
ID: 39830338
This was exactly what I needed.  I'm slowly learning JQuery and this helped!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question