So I have a bunch of divs that are hidden on load unless a checkbox is ticked.
It works on the change event, but on the refresh of the page the divs return hidden unless you turn the checkbox off and then back on.
I was wondering if there is a way to check which checkbox is ticked on load and then display:block, rather than ticking and unticking.
HTML/PHP
<div class="misc-pub-section">
<label><b>Year of release</b></label>
<input name="review_release_year" value="<?php echo $review_release_year; ?>" />
</div>
<div class="misc-pub-section">
<label><b>Director/Author/Company/Developer</b></label>
<input name="review_owner" value="<?php echo $review_owner; ?>" />
</div>
<div class="misc-pub-section">
<label><b>Generic Website Link</b></label>
<input name="review_website_link" value="<?php echo $review_website_link; ?>" />
</div>
<div class="misc-pub-section feature-short-webseries" style="display:none;">
<label><b>IMDb Title Link</b></label><br/>
<em style="color: #999;">imdb.com/title/</em><input size="9" name="review_imdb_link" value="<?php echo $review_imdb_link; ?>" />
</div>
<div class="misc-pub-section feature-short-webseries" style="display:none;">
<label><b>Story rating (out of 5)</b></label>
<input max="5" name="review_story_rating" value="<?php echo $review_story_rating; ?>" />
</div>
<div class="misc-pub-section feature-short-webseries-videogame" style="display:none;">
<label><b>Enjoyment rating (out of 5)</b></label>
<input max="5" name="review_enjoy_rating" value="<?php echo $review_enjoy_rating; ?>" />
</div>
<div class="misc-pub-section feature-short" style="display:none;">
<label><b>Soundtrack rating (out of 5)</b></label>
<input max="5" name="review_sound_rating" value="<?php echo $review_sound_rating; ?>" />
</div>
<div class="misc-pub-section webseries" style="display:none;">
<label><b>Attention span rating (out of 5)</b></label>
<input max="5" name="review_span_rating" value="<?php echo $review_span_rating; ?>" />
</div>
<div class="misc-pub-section hardware-software" style="display:none;">
<label><b>Features rating (out of 5)</b></label>
<input max="5" name="review_features_rating" value="<?php echo $review_features_rating; ?>" />
</div>
<div class="misc-pub-section hardware-software" style="display:none;">
<label><b>Function rating (out of 5)</b></label>
<input max="5" name="review_function_rating" value="<?php echo $review_function_rating; ?>" />
</div>
<div class="misc-pub-section hardware-software" style="display:none;">
<label><b>Value rating (out of 5)</b></label>
<input max="5" name="review_value_rating" value="<?php echo $review_value_rating; ?>" />
</div>
<div class="misc-pub-section software" style="display:none;">
<label><b>Operating System</b></label>
<input name="review_system_rating" value="<?php echo $review_system_rating; ?>" />
</div>
<div class="misc-pub-section videogame" style="display:none;">
<label><b>Graphics rating (out of 5)</b></label>
<input max="5" name="review_graphics_rating" value="<?php echo $review_graphics_rating; ?>" />
</div>
<div class="misc-pub-section videogame" style="display:none;">
<label><b>Gameplay rating (out of 5)</b></label>
<input max="5" name="review_gameplay_rating" value="<?php echo $review_gameplay_rating; ?>" />
</div>
jQuery
$(function() {
var a = $("#in-review-type-14"), b = $("#in-review-type-67"), f = $("#in-review-type-68"), d = $("#in-review-type-69"), e = $("#in-review-type-70"), c = $("#in-review-type-71"), h = $("#review-typechecklist input");
$(h).change(function() {
a.is(":checked") || b.is(":checked") || c.is(":checked") ? $(".feature-short-webseries").show() : $(".feature-short-webseries").hide();
a.is(":checked") || b.is(":checked") || c.is(":checked") || e.is(":checked") ? $(".feature-short-webseries-videogame").show() : $(".feature-short-webseries-videogame").hide();
a.is(":checked") || b.is(":checked") ? $(".feature-short").show() : $(".feature-short").hide();
c.is(":checked") ? $(".webseries").show() : $(".webseries").hide();
f.is(":checked") || d.is(":checked") ? $(".hardware-software").show() : $(".hardware-software").hide();
d.is(":checked") ? $(".software").show() : $(".software").hide();
e.is(":checked") ? $(".videogame").show() : $(".videogame").hide()
})
});
If the logic for the change event handler function already works correctly all you need to do is trigger that event handler when the page loads (after it has been bound):
$(h).change(function() {
...
}).trigger('change');
On an unrelated note, ternary operators are generally used for storing or passing values based on a condition, rather than branching execution (that's what an if statement is for). Your code will work, you'll just get errors if you run it through a tool such as JSLint it will complain about it.
You need to create cookie for every check box option.
For example if you check one option and DIV is visible now, then create cookie for that DIV call it something related to that DIV and set it's content to something that will associate yo that it is ON like true.
Then when reloading page check in php if that cookie exists and it's content = true and if that set style display to block of that particular DIV.
For turning off visibility you can either set cookie time to -x seconds to make it expired or update cookie content to false.
You can make cookie with javascript on same page on which you click those checkbox-es no need for reloading.
Every loading of the page erases the DOM so you must save temps data in cookies.
Related
Can you guys double check my codes. When I clicked the Update button it told me that the update was successful but when I look at my database nothing changed. I know I'm doing something wrong. Hope you guys help me to figure it out. Thanks.
I am still learning and it's an honor to learn from you guys. Please be nice and use basic terms hehe
<html>
<body>
<div>
<form action="edit.php?id=<?php echo $id;?>" method="post">
<div>
<label for="prov">Provinces</label><br>
<select id="prov"type="text" name="provi1">
<option><?php echo $provi; ?></option>
<option value="Isabela">Isabela</option>
<option value="La Union">La Union</option>
<option value="Pangasinan">Pangasinan</option>
<option value="Ilocos Sur">Ilocos Sur</option>
<option value="Ilocos Norte">Ilocos Norte</option>
</select>
</div>
<div>
<label>Date</label><br>
<input type="date" name="date" value="">
</div>
<div>
<label>Typhoon Name</label><br>
<input type="text" name="typhoon" value="<?php echo $typhoon; ?>">
</div>
<div>
<label>Warning #</label><br>
<input type="text" name="warning" value="<?php echo $warning; ?>">
</div>
<div>
<label for="prov">SS Height</label><br>
<label>2-3 meters
<input type="radio" name="meter" value="2-3 Meters"
<?php if ($ssh == '2-3 Meters') echo 'checked="checked"'; ?>>
</label>
<label>1-2 meters
<input type="radio" name="meter" value="1-2 Meters"
<?php if ($ssh=='1-2 Meters') echo 'checked="checked"'; ?>>
</label>
<label>< 1 meter
<input type="radio" name="meter" value="< 1 Meter"
<?php if ($ssh=='< 1 Meter') echo 'checked="checked"'; ?>>
</label><br>
<label for="imp">Impacts</label><br>
<textarea id="imp" type="text" name="impact1"><?php echo $impact; ?></textarea>
<label for="adv" >Advice</label><br>
<textarea id="adv" type="text" name="advice1"><?php echo $advice; ?></textarea>
</div>
<div class="form-group">
<input type="submit" value="Update" name="update">
<input type="reset" value="Cancel">
</div>
</form>
</div>
</body>
</html>
Fix the MySQL injection, or I WILL come and erase your database. (See comments under question).
Then (and only AFTER you fixed that):
You are using id from the $_GET, but for the update your ID comes from $_POST. However, you forgot to put that <input name='id' value='<?=$edit?>' type='hidden'> within your form. So there is no $_POST['id'], so it only updates all records with an empty id. And says: "Yay, I succesfully updated 0 records!". Hence no error: it was an overwhelming success. ;)
You seem to be confused about the id. There is no need for an $edit, an $id and an $u_id variable. It is all the same id. Your<FORM ACTION=... actually puts ?id= (empty string) behind the URL, since you emptied $id.
I'm am developing a project in php but my java is not good. I am trying to link two pages. The first page has a buttons including "Other" for donations which should work in a way that a user should click the button be redirected to the next page where the input text field for the amount should not be disabled.
I hope you are able to assist me because i read almost every post here about onclick events and other options and tried them but to no luck.
//Code for the other button
<td style="padding: 6px;">
<span>
<form action="getcreditcard.php" method="POST">
<input type="hidden" value="<?php echo base64_encode(6); ?>" name="id">
<button type="submit" id="donate" value="Other" class="btn btn-warning" style="width: 100%;">Other</button>
</form>
</span>
</td>
//Code for the receiveing page getcreditcard.php
<
} else if (base64_decode($_POST['id']) == 6) {
$p_price ='Add Amount Here.';
$p_currency = 'USD';
$p_name = 'Donation Option 5';
}
>
and
<div class="form-row">
<label>
<span>Amount (USD)</span>
<input type="text" name="amount"placeholder="enter amount " value="$ <?php echo $p_price; ?>" disabled="true" required="true">
</label>
</div>
Use the javascript jquery prop() like this:
<!-- simple example: -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<form>
Input:
<input type="text" name="amount" id="amount" placeholder="enter amount " value="$ <?php echo $p_price; ?>" required>
</form>
<script type="text/javascript">
$(document).ready(function(){
$("#amount").prop("disabled", true);
});
</script>
Can you use readonly
i hope this help you.
<input type="text" readonly value="<?php echo base64_encode(6); ?>" name="id">
how to remove field using jQuery?
I have to fetch record from a table using for each loop php-codeigniter
and my view looks like shown below attached pic.
when I click to remove button then remove corresponding input row field? how do we use jQuery?
currently i have click on remove button than remove all inputs fiels,
$(document).on('click', '.RemoveBtn', function() {
$(this).closest('div').remove();
});
and this is my view
<div class="col-md-7">
<?php
if (!empty($marks)) {
foreach ($marks as $key => $value) {
?>
<input name="mytext1[]" placeholder="Marks1" required="" value="<?php echo $value->marks1 ?>"
class="right" type="number"/>
<input name="mytext2[]" placeholder="Marks2" required="" value="<?php echo $value->marks2 ?>"
class="right" type="number"/>
<input name="mytext3[]" placeholder="Marks3" required="" value="<?php echo $value->marks3 ?>"
class="right" type="number"/>
<span class="text-left"></span>
<input type="button" value="Remove" class='RemoveBtn'/>
<?php
}
}
?>
</div>
You need to wrap it in a single div.
<div class="col-md-7">
<?php
if (!empty($marks)) {
foreach ($marks as $key => $value) {
?>
<div class="mainDiv">
<input name="mytext1[]" placeholder="Marks1" required="" value="<?php echo $value->marks1 ?>"
class="right" type="number"/>
<input name="mytext2[]" placeholder="Marks2" required="" value="<?php echo $value->marks2 ?>"
class="right" type="number"/>
<input name="mytext3[]" placeholder="Marks3" required="" value="<?php echo $value->marks3 ?>"
class="right" type="number"/>
<span class="text-left"></span>
<input type="button" value="Remove" class='RemoveBtn'/>
</div>
<?php
}
}
?>
</div>
JS
$(document).ready(function(){
$(document).on('click', '.RemoveBtn', function() {
$(this).parent('.mainDiv').remove();
});
});
what has to be done is, need to hit a ajax call from that button. like :
$('.button').on('click',function(){
$.get('your url',{id:$(this).data('id')});
})
Keep primary id with each button. (make login accordingly).
Apply php logic their, and have it accordingly. kindly be aware of security issues, its highly insecure to do so.
I want to keep the data in a text box after submit and inserted into db.
even if i refresh the page data should not change or empty
here is my code
<tr class="form-field1">
<th valign="top" scope="row">
<label for="approved_admin"><?php _e('Collaboration Admin', 'custom_table_example')?></label>
</th>
<td>
<input id="approved_admin" name="approved_admin" type="email" value="<?php echo esc_attr($item['approved_admin'])?>"size="50" class="code" placeholder="<?php _e('Admin Email', 'custom_table_example')?>" required>
</td>
</tr>
if i do this data will be there if i reload empty text box will be shown.I need to make this readonly and onload same text should be there.
Form
<form id="form" method="POST">
<input type="hidden" name="nonce" value="<?php echo wp_create_nonce(basename(__FILE__))?>"/>
<?php /* NOTICE: here we storing id to determine will be item added or updated */ ?>
<input type="hidden" name="sid" value="<?php echo $item['sid'] ?>"/>
<div class="metabox-holder" id="poststuff">
<div id="post-body">
<div id="post-body-content">
<?php /* And here we call our custom meta box */ ?>
<?php do_meta_boxes('Settings', 'normal', $item); ?>
<input type="submit" value="<?php _e('Save', 'custom_table_example')?>" id="submit" class="button-primary" name="submit" / >
<input type="submit" value="<?php _e('Edit', '')?>" id="edit" class="button-primary" name="edit" / >
</div>
</div>
</div>
</form>
I tried doing
<input type="email" name="approved_admin" value="<?php if (isset($_POST['approved_admin'])) { echo $_POST['approved_admin']; } ?>">
and also
<input type="text" name="country" value="Norway" <?php isset($approved_admin) ? echo 'readonly' : ''; ?> >
You can save data after page reload a lot of ways like... Session , cookie, get , post. After this value get by isset and echo .
In your case Post method used..
Try this working fine all thing
<input type="text" name="country" value=" <?php echo isset($_POST['country']) ? $_POST['country'] : ''; ?>" <?php echo isset($_POST['country']) ? 'readonly' : ''; ?> >
You just put field name in isset();
You can use this syntax. Have a try for this.
<input type="text" id="to_date" name="to_date" class="form-control" placeholder="Enter End Date" value="<?php echo isset($_POST['to_date']) ? $_POST['to_date'] : '' ?>" />
The name of the input type has to be mentioned in the isset() condition.
i'm new in coding joomla components i'm coding my first component at all and starting my knowledge from 0 in PHP
in my component i have 4 file uploaders (3 for images/pdf/etc.. and 1 for videos) and i would like to add a button to remove the file in case the person doesn't want the file anymore
can help me in this ?
here's the code of the form page:
<div class="control-group">
<div class="control-label"><?php echo $this->form->getLabel('video'); ?></div>
<div class="controls"><?php echo $this->form->getInput('video'); ?></div>
</div>
<?php if (!empty($this->item->video)) : ?>
[View File]
<?php endif; ?>
<input type="hidden" name="jform[video]" id="jform_video_hidden" value="<?php echo $this->item->video ?>" /> <input type="hidden" name="jform[ordering]" value="<?php echo $this->item->ordering; ?>" />
<input type="hidden" name="jform[state]" value="<?php echo $this->item->state; ?>" />
<input type="hidden" name="jform[checked_out]" value="<?php echo $this->item->checked_out; ?>" />
<input type="hidden" name="jform[checked_out_time]" value="<?php echo $this->item->checked_out_time; ?>" />
Any further information you need ask and i'll provide it
In your controller file, you should add a function called deleteImage that will delete the image from the filesystem. In your layout file (your view's template, as in "default.php"), you should add a link next to each uploaded file that goes like this:
index.php?option=com_pressrelease&task=deleteImage&id=imageId