Solved

PHP Sticky For to pass variable to JQuery

Posted on 2014-01-28
4
401 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 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
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
Comment Utility
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
...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
Comment Utility
This was exactly what I needed.  I'm slowly learning JQuery and this helped!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now