Solved

PHP Sticky For to pass variable to JQuery

Posted on 2014-01-28
4
402 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
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 109

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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.

770 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