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
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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
converting numbers with php 3 28
PHP warning 4 30
Session timeout 5 13
jquery to restrict certain words from input in form 11 12
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…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

911 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

16 Experts available now in Live!

Get 1:1 Help Now