/    Sign up×
Community /Pin to ProfileBookmark

Checkbox Problem

Hi Sir/Ma’am,

Good day!

I made a checkbox and I use jquery on displaying one textbox if the user check the Yes checkbox but if the user check the no the textbox will be hide. It works fine now but when the checkbox has vale from the database and which is no the textbox was displayed so that I made a if condition that only if the checkbox is Yes or ” but I noticed that when I check the Yes the textbox was not display because from the database the value of textbox is No.

[CODE]
$(document).ready(function() {
$(“.ticket”).change(function () {
//check if its checked. If checked move inside and check for others value

if (this.checked && this.value === “Yes”) {
//add a text box next to it
$(“#destination_data”).show();
}
else if (this.checked && this.value === “No”) {
//remove if unchecked
$(“#destination_data”).hide();
}

});
});

if($ticket == ”)
{
?>
#destination_data {display: none; display:}
<?php
}
?>

<tr>
<td class=”row_leaveform”>Travel Tickets:</td>
<td class=”row_leavedata”>
<input type=”checkbox” class=”ticket” name=”ticket” value=”Yes” <?php if($ticket==”Yes”) echo ‘checked=”checked”‘; ?>>Yes
<input type=”checkbox” class=”ticket” name=”ticket” value=”No” <?php if($ticket==”No”) echo ‘checked=”checked”‘; ?>>No
</td>
</tr>

<tr id=”destination_data”>
<?php
if($ticket==”Yes” || $ticket==”)
{
?>
<td class=”row_leaveform”>Destination </td>
<td class=”row_leavedata”><b>Doha</b> to <input type=”text” name=”destination” id=”destination” value=”<?php echo $nationality; ?>” size=”31″></td>
<?php
}
?>
</tr>
[/CODE]

it works fine when $ticket == ”;

but when in terms of update and the $ticket has value of No

in this code the destination was not display but when I try to check the Yes the destination was not display. I want it to display once I click the Yes if need to update my data.

if my remove the if condition even the value of ticket is No the destination was display ?

I want to happen is if

$ticket == ” or $ticket == ‘Yes’ the destination display
$ticket == ‘No’ destination not display but when I click the Yes the destination should be display

Thank you.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmOct 19.2015 — NO idea what you want.
Copy linkTweet thisAlerts:
@NoEffinWayOct 19.2015 — It seems you are mixing PHP and jQuery. While this isn't technically wrong, depending on how you do it, it is best to separate your server side code (php) with your client side code (jQuery/Javascript). Consider making AJAX call after the page is loaded to send and receive data.
×

Success!

Help @newphpcoder spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...