Solved

PHP Sticky For to pass variable to JQuery

Posted on 2014-01-28
4
405 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 110

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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

685 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