passing php variable to javascript onclick function - javascript

Not able to pass the php variable into javascript function.
<p id = "demo"><?php echo $color; ?></p><br>
<?php while($rows = mysqli_fetch_array($result)) {
$color = $rows["clr"];
?>
<ul id="menu">
<li>
<h onclick="myFunction('<?php echo $color; ?>');">
<input type ="radio" name="radio" id ="php" value="<?php echo $color;?>">
<?php echo $color; ?>
<!--//<label for = "php" type:<?php echo $rpproduct_typ_color; ?>></label>-->
</h>
</li>
</ul>
<script type="text/javascript" >
function myFunction(a) {
document.getElementById('demo').innerHTML = a;
}
</script>
<?php } ?>
But this way it works fine:-
<ul id="menu">
<li>
<input type ="radio" name="radio" id ="php" value="<?php echo $color; ?>" onClick="document.getElementById('demo').innerHTML=this.value"> <?php echo $color; ?>
<!--//<label for = "php" type:<?php echo $color; ?> ></label>-->
</li>
</ul>
But i want to pass multiple values to the onClick function i want the firs tone to work

You have not closed the braces of the line:
<?php while($rows = mysqli_fetch_array($result))
{
The element does not exists, hence I made it a paragraph.
<p id="demo">EMPTY</p>
<br />
<ul id="menu">
<?php
$colours = array( '#FF0000', '#00FF00', '#0000FF' );
foreach( $colours AS $colour ) {
?><li>
<p onClick="changeColour('<?php echo $colour; ?>')">
<input type ="radio" name="radio" value="<?php echo $colour; ?>">
<?php echo $colour; ?>
</p>
</li>
<?PHP } ?>
</ul>
<script type="text/javascript" >
function changeColour( a ) {
document.getElementById('demo').innerHTML = a;
}
</script>
Tested and working

Did you mistake h for a headline h1..h6 maybe? Since there is no h tag in HTML, at least none that I know of. However, I'd suggest using a block-level element instead, such as div or p.
<li>
<p onclick="myFunction('<?php echo $color; ?>');">
<input type ="radio" name="radio" id ="php" value="<?php echo $color;?>">
<?php echo $color; ?>
</p>
</li>
This would give me an output such as this, which works fine in Opera:
<li>
<p onclick="myFunction('red');" style="background-color: red;">
<input type ="radio" name="radio" id ="php" value="red"> red
</p>
</li>
<li>
<p onclick="myFunction('blue');" style="background-color: blue;">
<input type ="radio" name="radio" id ="php" value="blue"> blue
</p>
</li>

Related

OpenCart Set language through URL

When I select my language from the dropdown flag the opencart translates to the new language and I get directed to the index page.
I want to stay on the current page.
I found an article for this issue but I couldn`t make it work.
Link
This is my current code from catalog/controller/module/language.php
<?php if (count($languages) > 1) { ?>
<!-- Language -->
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="language_form">
<div class="dropdown">
<?php foreach ($languages as $language) { ?>
<?php if ($language['code'] == $code) { ?>
<?php echo $language['name']; ?>
<?php } ?>
<?php } ?>
<ul class="dropdown-menu">
<?php foreach ($languages as $language) { ?>
<li><?php echo $language['name']; ?></li>
<?php } ?>
</ul>
</div>
<input type="hidden" name="code" value="" />
<input type="hidden" name="redirect" value="<?php echo $redirect; ?>" />
</form>
<?php } ?>

undefined ids after language change [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 7 years ago.
Hello i need your help or advice about one of my problem , so the thing is i have a multi language website (2 languages for now) and have a ad posting form witch starts on http://newproject.comli.com/step1.php and goes to a step2 and the problem starts if i change language on a step2 file its gives me an error like : enter image description here
you wont see those errors on a hosting but there will be no result ether .
so basically i am sending a ids from s step1 to a step2 , ids of user selection to display a category witch they select and later to insert to a database ware get those errors as well if i try to change a language after insert ( i mean i got them inserted into database and then if i change a language its gives me a tons of error it could be moved to a another page if you are trying to change language or just another way to avoid those errors ) the insertions page is ready but i didt create a table for it on my hosting so it wont work there
this is my pages code just to be more understandable what i am talking about and ware is the problem :
step1.php
<?php
include_once 'common.php';
?>
<!DOCTYPE html>
<html lang="<?php echo $lang['LANG']; ?>">
<head>
<title><?php echo $lang['PAGE_TITLE']; ?></title>
<meta charset="UTF-8">
<link rel="stylesheet" href="styles.css">
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="js/ism-2.1.js"></script>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function() {
$(".level2 > li").hide();
$(".level1 > li").on("click", function() {
$(this).siblings().css("background-color", "transparent");
$(this).css("background-color", "#f1f1f1");
idx = $(this).index();
$(".level2 > li").hide();
$(".level2 > li").eq(idx).show();
});
$(".level3").hide();
$(".level2 > li > ul > li").on("click", function() {
$(".level2 > li > ul > li").css("background-color", "transparent");
$(this).css("background-color", "#f1f1f1");
$(".level3").hide();
var idx2 = $(this).index();
var idx1 = $(this).parent().parent().index();
$(".level3").show();
$("#catid").val("CAT" + (idx1+1) + "-" + (idx2+1));
});
});
</script>
</head>
<body>
<div class="advtop">
</div>
<div id="topbar2">
<div id="lang">
<ul>
<li>
<a href="?lang=lt" ><img src="image/Lithuania.png" ></a>
</li>
<li>
<img src="image/United Kingdom.png" >
</li>
</ul>
</div>
<div id="text">
<ul>
<li>
<?php
if(isset($_SESSION["username"]) && time() - $_SESSION["CREATED"] < 1800){
echo "Sveiki"; ?> <?php echo $_SESSION["username"]; ?><?php
}else {
?> <a href="post.php" ><?php echo $lang['LOGIN']; ?></a> <?php
}
?><span> |</span>
</li>
<li>
&bigtriangledown;</span>
<ul class="dropdown">
<li><a class="first" href="#"><?php echo $lang['FAV']; ?> (0)</a></li>
<li><?php echo $lang['ADS']; ?></li>
<li><?php echo $lang['DETAILS']; ?></li>
<li>
<?php
if(isset($_SESSION["username"]) && time() - $_SESSION["CREATED"] < 1800){
?> <a href="logout.php" ><?php echo $lang['LOGOUT']; ?></a> <?php
}else {
?> <a href="post.php" ><?php echo $lang['REGISTER']; ?></a> <?php
} ?>
</li>
</ul>
</li>
</ul>
</div>
<div id="postadv">
<a href="<?php
if(isset($_SESSION["username"]) && time() - $_SESSION["CREATED"] < 1800){
echo "step1.php";
}else {
echo "post.php";
}
?>" ><?php echo $lang['POST']; ?></a>
</div>
</div>
<div id="logo2"><img src="image/logo.png"></div>
<div id="searchbox2">
<form class="form" action="search.php" method="get">
<input class="search-field" type="search" name="search" size="70" maxlength="50" placeholder="<?php echo $lang['SRC']; ?>" height="50">
<select class="categories" name="categories">
<option value="0" selected="selected"><?php echo $lang['ALLCAT']; ?></option>
<option value="1"><?php echo $lang['CAT1']; ?></option>
<option value="2"><?php echo $lang['CAT2']; ?></option>
<option value="3"><?php echo $lang['CAT3']; ?></option>
<option value="4"><?php echo $lang['CAT4']; ?></option>
<option value="5"><?php echo $lang['CAT5']; ?></option>
<option value="6"><?php echo $lang['CAT6']; ?></option>
<option value="7"><?php echo $lang['CAT7']; ?></option>
<option value="8"><?php echo $lang['CAT8']; ?></option>
<option value="9"><?php echo $lang['CAT9']; ?></option>
</select>
<input class="submit-button" type="submit" value="<?php echo $lang['SRCBTN']; ?>">
</form>
<a href="#" ><?php echo $lang['ADVSRC']; ?></a>
</div>
<div id="itemsCategLists">
<ul class="level1">
<li>
<span><?php echo $lang['CAT1']; ?></span>
<i class="fa fa-chevron-right"></i>
</li>
<li>
<span><?php echo $lang['CAT2']; ?></span>
<i class="fa fa-chevron-right"></i>
</li>
<li>
<span><?php echo $lang['CAT3']; ?></span>
<i class="fa fa-chevron-right"></i>
</li>
<li>
<span><?php echo $lang['CAT4']; ?></span>
<i class="fa fa-chevron-right"></i>
</li>
<li>
<span><?php echo $lang['CAT5']; ?></span>
<i class="fa fa-chevron-right"></i>
</li>
<li>
<span><?php echo $lang['CAT6']; ?></span>
<i class="fa fa-chevron-right"></i>
</li>
<li>
<span><?php echo $lang['CAT7']; ?></span>
<i class="fa fa-chevron-right"></i>
</li>
<li>
<span><?php echo $lang['CAT8']; ?></span>
<i class="fa fa-chevron-right"></i>
</li>
<li>
<span><?php echo $lang['CAT9']; ?></span>
<i class="fa fa-chevron-right"></i>
</li>
</ul>
<ul class="level2">
<li>
<ul class="level2list1">
<li><span><?php echo $lang['CAT1-1']; ?></span></li>
<li><span><?php echo $lang['CAT1-2']; ?></span></li>
<li><span><?php echo $lang['CAT1-3']; ?></span></li>
<li><span><?php echo $lang['CAT1-4']; ?> </span></li>
</ul>
</li>
<li>
<ul class="level2list1">
<li><span><?php echo $lang['CAT2-1']; ?></span></li>
<li><span><?php echo $lang['CAT2-2']; ?></span></li>
<li><span><?php echo $lang['CAT2-3']; ?></span></li>
<li><span><?php echo $lang['CAT2-4']; ?></span></li>
<li><span><?php echo $lang['CAT2-5']; ?></span></li>
<li><span><?php echo $lang['CAT2-6']; ?></span></li>
<li><span><?php echo $lang['CAT2-7']; ?></span></li>
<li><span><?php echo $lang['CAT2-8']; ?></span></li>
</ul>
</li>
<li>
<ul class="level2list1">
<li><span><?php echo $lang['CAT3-1']; ?></span></li>
<li><span><?php echo $lang['CAT3-2']; ?></span></li>
<li><span><?php echo $lang['CAT3-3']; ?></span></li>
<li><span><?php echo $lang['CAT3-4']; ?></span></li>
<li><span><?php echo $lang['CAT3-5']; ?></span></li>
<li><span><?php echo $lang['CAT3-6']; ?></span></li>
<li><span><?php echo $lang['CAT3-7']; ?></span></li>
<li><span><?php echo $lang['CAT3-8']; ?></span></li>
</ul>
</li>
<li>
<ul class="level2list1">
<li><span><?php echo $lang['CAT4-1']; ?></span></li>
<li><span><?php echo $lang['CAT4-2']; ?></span></li>
<li><span><?php echo $lang['CAT4-3']; ?></span></li>
<li><span><?php echo $lang['CAT4-4']; ?></span></li>
<li><span><?php echo $lang['CAT4-5']; ?></span></li>
<li><span><?php echo $lang['CAT4-6']; ?></span></li>
<li><span><?php echo $lang['CAT4-7']; ?></span></li>
</ul>
</li>
<li>
<ul class="level2list1">
<li><span><?php echo $lang['CAT5-1']; ?></span></li>
<li><span><?php echo $lang['CAT5-2']; ?></span></li>
<li><span><?php echo $lang['CAT5-3']; ?></span></li>
<li><span><?php echo $lang['CAT5-4']; ?></span></li>
<li><span><?php echo $lang['CAT5-5']; ?></span></li>
</ul>
</li>
<li>
<ul class="level2list1">
<li><span><?php echo $lang['CAT6-1']; ?></span></li>
<li><span><?php echo $lang['CAT6-2']; ?></span></li>
<li><span><?php echo $lang['CAT6-3']; ?></span></li>
<li><span><?php echo $lang['CAT6-4']; ?></span></li>
<li><span><?php echo $lang['CAT6-5']; ?></span></li>
<li><span><?php echo $lang['CAT6-6']; ?></span></li>
<li><span><?php echo $lang['CAT6-7']; ?></span></li>
</ul>
</li>
<li>
<ul class="level2list1">
<li><span><?php echo $lang['CAT7-1']; ?></span></li>
<li><span><?php echo $lang['CAT7-2']; ?></span></li>
<li><span><?php echo $lang['CAT7-3']; ?></span></li>
<li><span><?php echo $lang['CAT7-4']; ?></span></li>
<li><span><?php echo $lang['CAT7-5']; ?></span></li>
<li><span><?php echo $lang['CAT7-6']; ?></span></li>
<li><span><?php echo $lang['CAT7-7']; ?></span></li>
</ul>
</li>
<li>
<ul class="level2list1">
<li><span><?php echo $lang['CAT8-1']; ?></span></li>
<li><span><?php echo $lang['CAT8-2']; ?></span></li>
<li><span><?php echo $lang['CAT8-3']; ?></span></li>
<li><span><?php echo $lang['CAT8-4']; ?></span></li>
<li><span><?php echo $lang['CAT8-5']; ?></span></li>
</ul>
</li>
<li>
<ul class="level2list1">
<li><span><?php echo $lang['CAT9-1']; ?></span></li>
<li><span><?php echo $lang['CAT9-2']; ?></span></li>
<li><span><?php echo $lang['CAT9-3']; ?></span></li>
<li><span><?php echo $lang['CAT9-4']; ?></span></li>
</ul>
</li>
</ul>
<div class="level3">
<form id="step1" action="step2.php" method="post">
<input type="hidden" name="catid" id="catid">
<input class="submit-button" type="submit" name="submint" value="<?php echo $lang['NEXT']; ?>">
</form>
</div>
</div>
<div class="footer2">
<div class="copy">
<ul>
<li>
<a href="#" ><?php echo $lang['TERMS']; ?></a>
</li>
<li>
<a href="#" ><?php echo $lang['CONTACT']; ?></a>
</li>
</ul>
<span style="font-size: 13px; color: black"><?php echo $lang['COPY']; ?></span>
</div>
</div>
</body>
</html>
and step2.php
<?php
include_once 'common.php';
?>
<!DOCTYPE html>
<html lang="<?php echo $lang['LANG']; ?>">
<head>
<title><?php echo $lang['PAGE_TITLE']; ?></title>
<meta charset="UTF-8">
<link rel="stylesheet" href="styles.css">
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="js/ism-2.1.js"></script>
</head>
<body>
<div class="advtop">
</div>
<div id="topbar2">
<div id="lang">
<ul>
<li>
<a href="?lang=lt" ><img src="image/Lithuania.png" ></a>
</li>
<li>
<img src="image/United Kingdom.png" >
</li>
</ul>
</div>
<div id="text">
<ul>
<li>
<?php
if(isset($_SESSION["username"]) && time() - $_SESSION["CREATED"] < 1800){
echo "Sveiki"; ?> <?php echo $_SESSION["username"]; ?><?php
}else {
?> <a href="post.php" ><?php echo $lang['LOGIN']; ?></a> <?php
}
?><span> |</span>
</li>
<li>
&bigtriangledown;</span>
<ul class="dropdown">
<li><a class="first" href="#"><?php echo $lang['FAV']; ?> (0)</a></li>
<li><?php echo $lang['ADS']; ?></li>
<li><?php echo $lang['DETAILS']; ?></li>
<li>
<?php
if(isset($_SESSION["username"]) && time() - $_SESSION["CREATED"] < 1800){
?> <a href="logout.php" ><?php echo $lang['LOGOUT']; ?></a> <?php
}else {
?> <a href="post.php" ><?php echo $lang['REGISTER']; ?></a> <?php
} ?>
</li>
</ul>
</li>
</ul>
</div>
<div id="postadv">
<a href="<?php
if(isset($_SESSION["username"]) && time() - $_SESSION["CREATED"] < 1800){
echo "step1.php";
}else {
echo "post.php";
}
?>" ><?php echo $lang['POST']; ?></a>
</div>
</div>
<div id="logo2"><img src="image/logo.png"></div>
<div id="searchbox2">
<form class="form" action="search.php" method="get">
<input class="search-field" type="search" name="search" size="70" maxlength="50" placeholder="<?php echo $lang['SRC']; ?>" height="50">
<select class="categories" name="categories">
<option value="0" selected="selected"><?php echo $lang['ALLCAT']; ?></option>
<option value="1"><?php echo $lang['CAT1']; ?></option>
<option value="2"><?php echo $lang['CAT2']; ?></option>
<option value="3"><?php echo $lang['CAT3']; ?></option>
<option value="4"><?php echo $lang['CAT4']; ?></option>
<option value="5"><?php echo $lang['CAT5']; ?></option>
<option value="6"><?php echo $lang['CAT6']; ?></option>
<option value="7"><?php echo $lang['CAT7']; ?></option>
<option value="8"><?php echo $lang['CAT8']; ?></option>
<option value="9"><?php echo $lang['CAT9']; ?></option>
</select>
<input class="submit-button" type="submit" value="<?php echo $lang['SRCBTN']; ?>">
</form>
<a href="#" ><?php echo $lang['ADVSRC']; ?></a>
</div>
<div id="itemsCategLists2">
<div class="post2" >
<form class="formstyle" action="final.php" method="post" >
<div class="adtext">
<p><b><?php echo $lang['KAT']; ?>:</b>
</p>
<p><b><?php echo $lang['ACTION']; ?>*:</b>
</p>
<p><b><?php echo $lang['ADTITLE']; ?>*:</b><br>
</p>
<p><b><?php echo $lang['ADDETAILS']; ?>*:</b>
</p><br><br><Br>
<p><b><?php echo $lang['PRICE']; ?>*:</b>
</p>
<p><b><?php echo $lang['ADPHOTOS']; ?>:</b>
</p>
<p><b><?php echo $lang['UARE']; ?>*:</b>
</p>
<p><b><?php echo $lang['PHONE']; ?>*:</b>
</p>
<p><b><?php echo $lang['EMAIL']; ?>:</b>
</p>
<p><b><?php echo $lang['LOCATION']; ?>*:</b>
</p>
<p><b><?php echo $lang['NAME']; ?>*:</b>
</p>
<p><b><?php echo $lang['WEB']; ?>:</b>
</p>
</div>
<div class="entry">
<?php
$catid = $_POST['catid'];
$catid2 = substr($catid,0,4);
$cat1 = $lang[$catid2];
$cat2 = $lang[$catid];
echo "<font color='grey'>".$cat1." » ".$cat2."</font>";
?>
<br style="margin-bottom: 17px;">
<input type="hidden" name="catid" value="<?php echo $catid; ?>">
<input type="radio" name="action" value="1" required> <?php echo $lang['PORPOSE']; ?>
<input type="radio" name="action" value="2" required> <?php echo $lang['LOOKING']; ?><br style="margin-bottom: 15px;">
<input type="text" name="title" maxlength="80" pattern=".{10,}" title="At Least 10 symbols" min="10" style="width: 379px;" required><br style="margin-bottom: 15px;">
<textarea name="details" rows="10" cols="30" pattern=".{10,}" title="At Least 10 symbols" style="width: 379px; height: 75px;" maxlength="5500" required></textarea><br><br style="margin-bottom: 5px;">
<input type="text" name="price" maxlength="10" pattern="\d+(\.\d{2})?" title="Only numbers" required><br style="margin-bottom: 15px;">
<input type="file" multiple="true" name="image[]"><br style="margin-bottom: 15px;">
<input type="radio" name="ocp" value="1" required><?php echo $lang['PRV']; ?>
<input type="radio" name="ocp" value="2" required><?php echo $lang['BSN']; ?><br style="margin-bottom: 15px;">
<input type="text" name="phonenumber" pattern="^\s*\(?(020[7,8]{1}\)?[ ]?[1-9]{1}[0-9{2}[ ]?[0-9]{4})|(0[1-8]{1}[0-9]{3}\)?[ ]?[1-9]{1}[0-9]{2}[ ]?[0-9]{3})\s*$" title="Only UK Phone numbers ( 07*********) " required><br style="margin-bottom: 15px;">
<input type="email" name="email"><br style="margin-bottom: 15px;">
<input type="text" name="location" pattern=".[A-Za-z]{3,15}" title="Only letter (4-15 symbols)" required><br style="margin-bottom: 15px;">
<input type="text" name="name" pattern=".[A-Za-z]{3,15}" title="Only letter (4-15 symbols)" required><br style="margin-bottom: 15px;">
<input type="text" name="web" pattern="www\.\w+\.\w{2,3}|www\.\w+\.\w{2,3}\.\w{2}" title="Format :(www.website.com) "><br style="margin-bottom: 15px;">
<input class="submit-button" type="submit" name="submit" value="<?php echo $lang['POSTADV']; ?>">
</div>
</form>
</div>
</div>
<div class="footer2">
<div class="copy">
<ul>
<li>
<a href="#" ><?php echo $lang['TERMS']; ?></a>
</li>
<li>
<a href="#" ><?php echo $lang['CONTACT']; ?></a>
</li>
</ul>
<span style="font-size: 13px; color: black"><?php echo $lang['COPY']; ?></span>
</div>
</div>
</body>
</html>
okay so i think a little and find a solution for this not the best one but its seams no1 else can help me except my self so what i will try to do is check if a catid is isset and if not then just redirect back to a step1 so if some1 try to access the step2 page it will just redirect to step1 because catid will be not isset and same with language when i change language catid becomes not isset and it should redirect me to step1 page , tell me if i am thinking a right way and if not what i am doing wrong

Ignore checkbox that is disable

I have here a code that when you clicked the All link it will check all the check boxes and when None it will uncheck all the check boxes.
But I have a PHP conditions that when the $pta_fee == $pta_fee_trans the check box will be disable, but when I clicked the All link, the disable check box appears to be checked.
How can I ignore the disable check box if I checked the All link?
<div class="sub_profile right">
<p class="sub_content_text" style='margin-left: 25px;'>
All | None
MISCELLANEOUS FEES:
</p>
<?php
if($pta_fee == $pta_fee_trans)
{
?>
<p class="sub_content_text" style='margin-left: 30px;'>
<input type='checkbox' value="<?php echo $pta_fee; ?>" disabled>
PTA Fee : ₱ <?php echo $pta_fee; ?></p>
<?php
}
else
{
?>
<p class="sub_content_text" style='margin-left: 30px;'>
<input type='checkbox' name='draw[]' value="<?php echo $pta_fee; ?>" id="required-checkbox1" onClick="CheckIfChecked(this.id)">
PTA Fee : ₱ <?php echo $pta_fee; ?></p>
<?php
}
if($maintenance_fee == $maintenance_fee_trans)
{
?>
<p class="sub_content_text" style='margin-left: 30px;'>
<input type='checkbox' value="<?php echo $maintenance_fee; ?>" disabled>
Maintenance Fee : ₱ <?php echo $maintenance_fee; ?></p>
<?php
}
else
{
?>
<p class="sub_content_text" style='margin-left: 30px;'>
<input type='checkbox' name='draw[]' value="<?php echo $maintenance_fee; ?>" id="required-checkbox2" onClick="CheckIfChecked(this.id)">
Maintenance Fee : ₱ <?php echo $maintenance_fee; ?></p>
<?php
}
if($id_school == $id_school_trans)
{
?>
<p class="sub_content_text" style='margin-left: 30px;'>
<input type='checkbox' value="<?php echo $id_school; ?>" disabled>
School ID : ₱ <?php echo $id_school; ?></p>
<?php
}
else
{
?>
<p class="sub_content_text" style='margin-left: 30px;'>
<input type='checkbox' name='draw[]' value="<?php echo $id_school; ?>" id="required-checkbox3" onClick="CheckIfChecked(this.id)">
School ID : ₱ <?php echo $id_school; ?></p>
<?php
}
if($electricity == $electricity_trans)
{
?>
<p class="sub_content_text" style='margin-left: 30px;'>
<input type='checkbox' value="<?php echo $electricity; ?>" disabled>
Electricity : ₱ <?php echo $electricity; ?></p>
<?php
}
else
{
?>
<p class="sub_content_text" style='margin-left: 30px;'>
<input type='checkbox' name='draw[]' value="<?php echo $electricity; ?>" id="required-checkbox4" onClick="CheckIfChecked(this.id)">
Electricity : ₱ <?php echo $electricity; ?></p>
<?php
}
?>
<div id="sub_profile_cont">
<div class="sub_profile left">
<p class="block_cont left">
<div id = "submit-button-container" style="display:none;">
<input class="action_btn" type="submit" name="submit" id="pay_btn" value="COMPUTE" onClick="setUpdateAction();"/>
</div>
<b style="display: none";><input class="action_btn" type="submit" name="submit" id="pay_btn" value="COMPUTE" onClick="setUpdateAction();"/></b>
</p>
</div>
</div>
</div>
--Here's the javascript code for checking all the check boxes:
<script>
function selectToggle(toggle, form) {
var myForm = document.forms[form];
for( var i=0; i < myForm.length; i++ ) {
if(toggle) {
myForm.elements[i].checked = "checked";
}
else {
myForm.elements[i].checked = "";
}
}
}
Try this:
<script>
function selectToggle(toggle, form) {
var myForm = document.forms[form];
for( var i=0; i < myForm.length; i++ ){
if(myForm.elements[i].disabled != true){
if(toggle){
myForm.elements[i].checked = "checked";
}
else{
myForm.elements[i].checked = "";
}
}
}
}

Jquery disable child element of the same parent

I don't want to copy any of the questions asked before, but I have hard time to solve my problem.
I have a form with few checkbox-es, some of them are hidden to trigger output when checkbox is unchecked. At the end of the page I have JQuery code, that should disable those hidden checkboxes if I enable general boxes, but this code doesn't work. Whenever I click to any checkbox, EVERY other checkboxes become unchecked! I think it happens because I cant aim to the only one needed element.
Maybe you didn't understand, but if you look at the code, you will find out exactly what is wrong!
<form action="" method="GET" name="<?php echo $listFilter['forn_name']; ?>" id="<?php echo $listFilter['forn_name']; ?>">
<span>
<input type="checkbox" value="1" name="word" id="word_checkbox" class="checkbox" <?php if($listFilter['word_status'] == 1){ ?> checked <?php } ?>/>
<input type='hidden' value='0' name='word' class="checkbox_hidden" <?php if($listFilter['word_status'] == 0){ ?> checked <?php } ?>/>
<label class="label" for="word_checkbox">Words</label>
</span>
<span>
<input type="checkbox" value="1" name="pron" id="pron_checkbox" class="checkbox" <?php if($listFilter['pronunciation_status'] == 1){ ?> checked <?php } ?> />
<input type='hidden' value='0' name='pron' class="checkbox_hidden" <?php if($listFilter['pronunciation_status'] == 0){ ?> checked <?php } ?>/>
<label class="label" for="pron_checkbox">Pronunciation</label>
</span>
<span>
<input type="checkbox" value="1" name="pos" id="pos_checkbox" class="checkbox" <?php if($listFilter['pos_status'] == 1){ ?> checked <?php } ?> />
<input type='hidden' value='0' name='pos' class="checkbox_hidden" <?php if($listFilter['pos_status'] == 0){ ?> checked <?php } ?>/>
<label class="label" for="pos_checkbox">Part of speech</label>
</span>
<span>
<input type="checkbox" value="1" name="meaning" id="meaning_checkbox" class="checkbox" <?php if($listFilter['meaning_status'] == 1){ ?> checked <?php } ?> />
<input type='hidden' value='0' name='meaning' class="checkbox_hidden" <?php if($listFilter['meaning_status'] == 0){ ?> checked <?php } ?>/>
<label class="label" for="meaning_checkbox">Meaning</label>
</span>
<span>
<input type="checkbox" value="1" name="examples" id="examples_checkbox" class="checkbox" <?php if($listFilter['examples_status'] == 1){ ?> checked <?php } ?> />
<input type='hidden' value='0' name='examples' class="checkbox_hidden" <?php if($listFilter['examples_status'] == 0){ ?> checked <?php } ?>/>
<label class="label" for="examples_checkbox">Examples</label>
</span>
<script>
$(document).ready(function(){
$("#<?php echo $listFilter['forn_name']; ?> .checkbox").change(function() {
/* I reckon those codes bellow are causing problem */
var parent = $(this).closest('span');
if(this.checked){$(this).parent("span").children(".checkbox_hidden").prop('disabled', true);}
document.forms.<?php echo $listFilter['forn_name']; ?>.submit();
});
});
</script>
</form>
Thanks to Alexander, there is a sample code on JSFiddle. http://jsfiddle.net/TH2hh/

Javascript change push input to click link (OpenCart Filters)

In the Opencart filters I would like to change the Input Box Push to a click link;
Here is what I have at the minute;
<?php foreach($filter_groups as $filter_group){ ?>
<div>
<ul>
<li><span id="filter-group<?php echo $filter_group['filter_group_id']; ?>"><?php echo $filter_group['name']; ?></span>
<ul>
<?php foreach($filter_group['filter'] as $filter){ ?>
<?php if(in_array($filter['filter_id'], $filter_category)){ ?>
<li>
<input type="checkbox" value="<?php echo $filter['filter_id']; ?>" class="item" id="filter<?php echo $filter['filter_id']; ?>" checked="checked" />
<label for="filter<?php echo $filter['filter_id']; ?>"><?php echo $filter['name']; ?></label>
</li>
<?php } else { ?>
<li>
<input type="checkbox" value="<?php echo $filter['filter_id']; ?>" class="item" id="filter<?php echo $filter['filter_id']; ?>" />
<label for="filter<?php echo $filter['filter_id']; ?>"><?php echo $filter['name']; ?></label>
</li>
<?php } ?>
<?php } ?>
</ul>
</li>
</ul>
</div>
<?php } ?>
<script type="text/javascript">
$(document).ready(function() {
$('.item').live('change', function(){
filter = [];
$('input[type=\'checkbox\']:checked').each(function(element) {
filter.push(this.value);
});
location = '<?php echo $action; ?>&filter=' + filter.join(',');
});
});
//--></script>
I am guessing the HTML will change to something like this;
<?php foreach($filter_groups as $filter_group){ ?>
<div>
<ul>
<li><span id="filter-group<?php echo $filter_group['filter_group_id']; ?>"><?php echo $filter_group['name']; ?></span>
<ul>
<?php foreach($filter_group['filter'] as $filter){ ?>
<?php if(in_array($filter['filter_id'], $filter_category)){ ?>
<li class="selected">
<?php echo $filter['name']; ?>
</li>
<?php } else { ?>
<li>
<?php echo $filter['name']; ?>
</li>
<?php } ?>
<?php } ?>
</ul>
</li>
</ul>
</div>
<?php } ?>
I just have no idea how to approaching changing to so it submits an onclick location change that preserves the existing filters. Are you able to assist me?
Yes, that is correct, the new HTML should work. To make it simpler (without need of JavaScript) You may fill in the href attribute to this dynamic value:
<?php echo $filter['name']; ?>
(no need of id attribute). Now on click the URL is directly triggered changing the filter to new filter_id.
Keep in mind that the default approach let's the user to check more than one filter value however with Your approach only one filter value could be selected at a time.
It might be also usefull to display the currently selected filter only as a text node so that it is not clickable, e.g. like this:
<?php if(in_array($filter['filter_id'], $filter_category)){ ?>
<li class="selected">
<span><?php echo $filter['name']; ?></span>
</li>
<?php } else { ?>
<li>
<?php echo $filter['name']; ?>
</li>
<?php } ?>

Categories