open a div having id using onclick in a hyperlink - php

below is the given div having id "panel" and links in the same page but outside this div, when I click on the link this div should be open. there are several links so jquery does not work and my button is created dynamically through php while loop hence i cannot put unique id in my hyperlink
<div id="panel">
<form name="userloginform" action="xxx.php" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" class="tb">
<tr>
<td align="left" valign="middle" height="80">User Name</td>
<td align="left" valign="middle">: </td>
<td align="left" valign="middle"><input name="user" type="text" class="log"/></td>
</tr>
<tr>
<td align="left" valign="middle">Password</td>
<td align="left" valign="middle">: </td>
<td align="left" valign="middle"><input name="pass" type="password" class="log"/></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="3"><input name="submit1" type="submit" value="Login" class="login_btn"/></td>
</tr>
</table>
</form>
</div>
and my link is
<a href="#" id="flip" >Launch Now</a>
<a href="#" id="" >Launch Now</a>
If I am not clear please reply which part is not clear so that I can edit and provide useful information clearly
ok here is where link is coming from, a CMS is used here.
<?php
$sql=mysql_query("SELECT * FROM heading ORDER BY id DESC");
while($r=mysql_fetch_array($sql))
{
$ii=$r['id'];
?>
<h3><?php echo $r['heading'];?></h3>
<div>
<div class="content">
<div class="main_table_wrapper">
<table width="1030" border="0" cellspacing="0" cellpadding="0" align="left">
<?php
$sql2=mysql_query("SELECT * FROM inner_table WHERE head='$ii'") ;
while($rows=mysql_fetch_array($sql2))
{
$abc=str_replace($rows['url'],'XXXXXXXXXXXXXXX',$rows['url']);
?>
<tr>
<th align="left" valign="middle" width="350"><?php echo $rows['inner_names'];?></th>
<th align="left" valign="middle" width="250"><?php echo $abc;?></th>
<th align="left" valign="middle" width="200"><?php echo $rows['author'];?></th>
<th align="center" valign="middle" width="100"><?php echo $rows['doe'];?></th>
<th align="right" valign="middle" width="130"><span class="lunch">Launch Now</span></th>
</tr>
<?php } ?>
</table>
</div>
</div>
</div>
<?php } ?>
</div>

You can't have multiple elements with the same id.
Since you didn't show any JS code so far, the only advice I can give is to use a class as the identifier for the action link.
From the look of your markup you could also use something along
$('span.lunch').on('click', 'a', function(e) { //do stuff } );

Related

How to list user types from within a database and allow selection from an administration panel?

I am trying to add an option in the backend of an administration panel where admins can change the user type. Called: Change User Type
Before these were the options available: Add Notes about Driver and Change Email :
I modified the php and added the front end selector to Change user type in the admin panel:
But the problem is that it keeps pulling a box to enter data. I want a list with all user types to be listed in a drop down so I can select a user type and change and not add notes to it.
In the database I only have three types of users "user_group". They are listed under Ids 1, 2, and 3.
MY QUESTION IS:
How can I make a drop down list appear, once I select Change User Type after already having selected the user under the Select Driver options in the previous drop down?
My user type ids are listed under user_group
Below is the current code on the file, which is not very much:
function fn_ACTION_METHOD(sMethod){
if(sMethod=='notes'){
document.getElementById('comment_box').style.display='block';
document.getElementById('email_box').style.display='none';
document.getElementById('btnSUBMIT').value='ADD NOTES';
}else if(sMethod=='email'){
document.getElementById('comment_box').style.display='none';
document.getElementById('email_box').style.display='block';
document.getElementById('btnSUBMIT').value='CHANGE EMAIL';
}else if(sMethod=='user_group'){
document.getElementById('comment_box').style.display='none';
document.getElementById('email_box').style.display='block';
document.getElementById('btnSUBMIT').value='ChangeType';
}
}
function fn_LOAD_EMAIL(iDriverID){
$.get("ajax_data.php", {action: 'load-email', did: iDriverID}, function(data){
if (data=="ERROR"){
$('#Message').html("Error!!! in loading driver email");
}else{
$('#txtemail').val(data);
}
}, 'html');
}
</script>
</head>
<body style="margin: 0px;">
<div align="center">
<table border="0" cellspacing="0" cellpadding="0">
<!--start header -->
<? include('inc_header.php'); ?>
<!-- start side nav -->
<!-- actual page -->
<td>
<table border="0" cellspacing="0" cellpadding="0" width="980">
<tr valign="top" align="left">
<td width="15" height="16"><img src="../assets/images/autogen/clearpixel.gif" width="15" height="1" border="0" alt=""></td>
<td width="1"><img src="../assets/images/autogen/clearpixel.gif" width="1" height="1" border="0" alt=""></td>
<td width="949"><img src="../assets/images/autogen/clearpixel.gif" width="683" height="1" border="0" alt=""></td>
<td width="15"><img src="../assets/images/autogen/clearpixel.gif" width="1" height="1" border="0" alt=""></td>
</tr>
<tr valign="top" align="left">
<td height="40"></td>
<td colspan="2" width="949">
<table border="0" cellspacing="0" cellpadding="0" width="949" style="background-image: url('../assets/images/banner.png'); height: 40px;">
<tr align="left" valign="top">
<td width="100%">
<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%">
<tr>
<td class="TextObject" align="center">
<h1 style="margin-bottom: 0px;">DRIVER NOTES & EMAIL CHANGE</h1>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr valign="top" align="left"><td colspan="4"> </td></tr>
<tr valign="top" align="left"><td colspan="4"> </td></tr>
<tr valign="top" align="left">
<td colspan="2"></td>
<td width="1050" class="TextObject" align="center">
<form name="frm1" action="driver_notes_email.php" method="post">
<input type="hidden" name="action" value="add_action" />
<table cellpadding="0" cellspacing="5" border="0" width="800" align="center" class="box">
<tr><td colspan="2" id="Message" width="100%"><?=$sMessage?></td></tr>
<tr>
<td class="label" width="200">Driver:</td>
<td width="800"><? fn_DISPLAY_USERS('drpdriver', 0, "200", "1", "--Select Driver--", "CONCAT(l_name, ' ', f_name) AS user_name", "l_name", $iGROUP_DRIVER.",".$iGROUP_COORDINATOR_STAFF, "fn_LOAD_EMAIL(this.value);");?></td>
</tr>
<tr>
<td class="label">Action:</td>
<td>
<div class="left"><input type="radio" id="opttype" name="optaction" value="ChangeType" onClick="fn_ACTION_METHOD('notes');"/></div>
<span class="label left">Change User Type</span>
<div class="left"><input type="radio" id="optnotes" name="optaction" value="Notes" onClick="fn_ACTION_METHOD('notes');"/></div>
<span class="label left">Add Notes about Driver</span>
<input type="radio" id="optreading" name="optaction" value="Change Email" onClick="fn_ACTION_METHOD('email');"/>
<span class="label">Change Email</span>
</td>
</tr>
<tr>
<td colspan="2">
<div id="email_box" style="display:none;">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td class="label" width="200">Email:</td>
<td width="400"><input type="text" id="txtemail" name="txtemail" value="" maxlength="150" style="width:250px;" /></td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td colspan="2">
<div id="comment_box" style="display:none; width:100%;">
<table cellpadding="0" cellspacing="5" border="0" width="100%">
<tr>
<td class="label" valign="top" width="200">Notes:</td>
<td width="400"><textarea name="txtcomments" id="txtcomments" cols="50" rows="10" style="width:250px;" ></textarea></td>
</tr>
</table>
</div>
</td>
</tr>
<tr><td colspan="2"> </td></tr>
<tr><td></td><td><input type="button" name="btnSUBMIT" id="btnSUBMIT" value="ACTION" class="Button" onClick="valid_action(this.form);" style="width:150px;" /></td></tr>
</table>
</form>
</td>
<td></td>
</tr>
</table>
</td>
<!-- end actual page -->
<!-- footer -->
<? include('inc_footer.php'); ?>
</table>
</td>
</tr>
</table>
</div>
</body>
</html>
Look in your html code where the div id equals email_box. This box is already on the page but is hidden. In your javascript you added for the 'change user type' you correctly changed the action button but you are still just showing the email_box div by calling style display = block
You need to add a new div which is hidden by default with a select box in it, and only show it when the radio button is clicked. You will also need to add your php code in to actually update the user when the form is submitted.

PHP DOM get element which contains

Need help with parsing HTML code by PHP DOM.
This is simple part of huge HTML code:
<table width="100%" border="0" align="center" cellspacing="3" cellpadding="0" bgcolor='#ffffff'>
<tr>
<td align="left" valign="top" width="20%">
<span class="tl">Obchodne meno:</span>
</td>
<td align="left" width="80%">
<table width="100%" border="0">
<tr>
<td width="67%">
<span class='ra'>STORE BUSSINES</span>
</td>
<td width="33%" valign='top'>
<span class='ra'>(od: 02.10.2012)</span>
</td>
</tr>
</table>
</td>
</tr>
</table>
What I need is to get text "STORE BUSINESS". Unfortunately, the only thing I can catch is "Obchodne meno" as a content of first tag, so according to this content I need to get its parent->parent->first sibling->child->child->child->child->content. I have limited experience with parsing html in php so any help will be valuable. Thanks in advance!
Make use of DOMDocument Class and loop through the <span> tags and put them in array.
<?php
$html=<<<XCOE
<table width="100%" border="0" align="center" cellspacing="3" cellpadding="0" bgcolor='#ffffff'>
<tr>
<td align="left" valign="top" width="20%">
<span class="tl">Obchodne meno:</span>
</td>
<td align="left" width="80%">
<table width="100%" border="0">
<tr>
<td width="67%">
<span class='ra'>STORE BUSSINES</span>
</td>
<td width="33%" valign='top'>
<span class='ra'>(od: 02.10.2012)</span>
</td>
</tr>
</table>
</td>
</tr>
</table>
XCOE;
$dom = new DOMDocument;
$dom->loadHTML($html);
foreach ($dom->getElementsByTagName('span') as $tag) {
$spanarr[]=$tag->nodeValue;
}
echo $spanarr[1]; //"prints" STORE BUSINESS

Only first row from sql query is displaying

My trying to show product desc in pop up. Mean when i click on product link then one pop up will open and show product desc. but here something is wrong. every product link showing first product desc. My code is Below. Please help me out.
Javascript:
<script language="JavaScript">
function displayPopup(alert_MSG)
{
var theDetail = document.getElementById('flyBox');
theDetail.style.display="block";
}
function closePopup(alert_MSG)
{
var theDetail = document.getElementById('flyBox');
if (theDetail.style.display=="block")
{
theDetail.style.display="none";
}
}
</script>
HTML:
View larger
<div id="flyBox" style="display:none;">
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="borderWindow">
<div class="container">
<div id="closeButton"><img src="http://i1122.photobucket.com/albums/l523/Long_Islander/flyBoxClose.png" width="28" height="28" alt="Close Button" border="0" /></div>
<div class="content">
<table width="600" border="0" cellspacing="20" cellpadding="0">
<tr>
<td>
<div id="myMessageBox" name="myMessageBox">
<table width="100%" border="0" cellspacing="2" cellpadding="0">
<tr>
<td class="colheadingL"><font color="white">Description</font></td>
</tr>
<tr>
<td ><?php echo $img; ?></td>
<td>Book Name:</td>
<td ><?php echo $row['pname']; ?></td>
<td class="text1">MRP:</td>
<td><?php echo $row['price'];?> </td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
But pop up is open click on hyperlink. but problem is showing only 1'st record in all product
You don't have loop any in your template script, that is why you see just one record vizualized.
I don't know exactly how your code is organized outside of the snippet you have posted, but assuming your data rows are in $rows array variable, the code will look something like that:
<? foreach($rows as $row) { ?>
<tr>
<td ><?php echo $img; ?></td>
<td>Book Name:</td>
<td ><?php echo $row['pname']; ?></td>
<td class="text1">MRP:</td>
<td><?php echo $row['price'];?> </td>
</tr>
<? } ?>
Try to make IDs of each DIV as Unique.
Below is the sample code, try to use it as per your requirement
<script language="JavaScript">
function displayPopup(id)
{
var theDetail = document.getElementById(id);
theDetail.style.display="block";
}
function closePopup(id)
{
var theDetail = document.getElementById(id);
if (theDetail.style.display=="block")
{
theDetail.style.display="none";
}
}
</script>
<?php for($i=0;$i<4;$i++){?>
<div>
View larger
<div id="flyBox_<?php echo $i;?>" style="display:none;">
<div id="closeButton"><img src="http://i1122.photobucket.com/albums/l523/Long_Islander/flyBoxClose.png" width="28" height="28" alt="Close Button" border="0" /></div>
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<?php echo "Div ".$i. " Content comes here";?>
</td>
</tr>
</table>
</div>
</div>
<?php }?>

Sending particular input value among input array into JavaScript

I am using a query to populate a list of messages by using a loop, here's my code:
<?php
$sql_i_msg_sent_waiting="SELECT t1.i_message_id,t2.username,t2.name,t2.propic,t2.age,t2.dob,t3.religion,t3.caste
FROM candidate_i_message as t1, candidate_register_table as t2, candidate_social_table as t3 WHERE t1.from_username='$_SESSION[logged_user]' AND t1.to_username=t2.username AND t2.username=t3.username AND t1.status='0'";
$result_i_msg_sent_waiting=mysql_query($sql_i_msg_sent_waiting,$con);
$count=mysql_num_rows($result_i_msg_sent_waiting);
echo $count;
?>
<div id="section_i_message_sent_waiting" style="width:650px; overflow:auto;">
<h2>Awaiting Sent Request</h2>
<?php
if(mysql_num_rows($result_i_msg_sent_waiting)==0)
{
?>
<div style="width:650px; border-bottom:1px solid #CCCCCC" align="center">
<table border='0' cellspacing='0' cellpadding='0' width='550px' align='center'>
<tr style='padding-botton:5px; border-bottom:1px solid #CCCCCC'>
<td width='50px'/>
<td><FONT COLOR=red FACE='Geneva, Arial' SIZE=2>
No Messages Found.</FONT></td>
<td width='50px'/></tr></table>
</div>
<?php
}
else
{
while($row_i_msg_sent_waiting=mysql_fetch_array($result_i_msg_sent_waiting))
{
?>
<div style="width:650px; border-bottom:1px solid #CCCCCC" align="center">
<table width="550px" cellpadding="0" cellspacing="0" border="2" align="center" style="vertical-align:middle">
<tr style='vertical-align:middle'>
<td style='vertical-align:middle' width="100px">
<form method='post' action='id.php' name='showid' id='showid'>
<input type='hidden' name='pro_username' id='pro_username'
value="<?php echo $row_i_msg_sent_waiting['username'];?>"/>
<input type='image' src='<?php echo $row_i_msg_sent_waiting['propic'];?> ' style="width:100px; vertical-align:middle"/>
</form>
</td>
<td style='vertical-align:middle;border-right:1px solid #CCCCCC;border-top:1px solid #CCCCCC' width="450px" >
<table width="450px" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="10px"/>
<td width="100px" align="left">Name</td>
<td width="10px">:</td>
<td width="100px" align="left"><?php echo $row_i_msg_sent_waiting['name'];?>
</td>
<td width="10px">
<td width="100px" align="left">Age</td>
<td width="10px">:</td>
<td width="100px" align="left"><?php echo $row_i_msg_sent_waiting['age'];?>
</td>
<td width="10px"/>
</tr>
<tr>
<td width="10px"/>
<td width="100px" align="left">Date Of Birth</td>
<td width="10px">:</td>
<td width="100px" align="left"><?php echo $row_i_msg_sent_waiting['dob'];?>
</td>
<td width="10px">
<td width="100px" align="left">Religion</td>
<td width="10px">:</td>
<td width="100px" align="left"><?php echo $row_i_msg_sent_waiting['religion'];?>
</td>
<td width="10px"/>
</tr>
<tr>
<td width="10px"/>
<td width="100px" align="left">Caste</td>
<td width="10px">:</td>
<td width="100px" align="left"><?php echo $row_i_msg_sent_waiting['caste'];?>
</td>
<td width="10px">
<td width="100px" align="left">Religion</td>
<td width="10px">:</td>
<td width="100px" align="left"><?php echo $row_i_msg_sent_waiting['religion'];?>
</td>
<td width="10px"/>
</tr>
<tr>
<td width="10px"/>
<td width="100px" align="left">Action</td>
<td width="10px">:</td>
<td width="100px" align="left">
<form method="post" name="cancel_request_form" id="cancel_request_form"
action="javascript:cancel_request(document.getElementById('cancel_request_form'));">
<input type="text" name="no_of_msg" id="no_of_msg" value="<?php echo $count;?>"/>
<input type="text" name="cancel_request[]" id="cancel_request[]"
value="<?php echo $row_i_msg_sent_waiting['i_message_id'];?>"/>
<input type="submit" name="cancel" id="cancel" class="button" style="width: 100px" value="Cancel Request"/>
</form>
</td>
<td width="10px">
<td width="100px" align="left"></td>
<td width="10px">:</td>
<td width="100px" align="left">
</td>
<td width="10px"/>
</tr>
</table>
</td>
</tr>
</table>
</div>
<?php
}
}?>
</div>
the line
<input type="text" name="cancel_request[]" id="cancel_request[]"
value="<?php echo $row_i_msg_sent_waiting['i_message_id'];?>"/>
creates a array of input type text, and each input text contains corressponding message_id...since each input text is contained within a form, and since the form is within a loop, the form is also repeatative..when the submit button will be clicked corressponding to a particular form, the input type text[] within that form will fire the value to get accepted in the javascript i give below...
<script>
function cancel_request(obj) {
alert(document.getElementByName('cancel_request[]').value);
}
</script>
But the script is showing problem, it's not working at all. I don't know what's wrong. It's not displaying anything. There is message_id 1 and 2: one text type input[] contains value 1, another value 2.
When I click the submit button corresponding to value 1, the value of that text type input will be send to JavaScript and displayed. What's the problem with my script?
The function is getElementsByName - Elements in the plural. You then access it like an array.

jquery and php to grab the contents from a selected row When onclick of a selected checbox

Attached the source code of PHP and jquery , gives undefined as alert ...later displays all the contents in the table... i need to just display the one which the user clicks on checkbox..... what mistake is in my code.
--------------------php---------------------------------------------------------
</script>
<script src="<?=base_url();?>js/calendar.js" type="text/javascript"></script>
<form name="inwardProductList" action="" method="post" >
<table width="100%" border="0" cellpadding="0" cellspacing="0" align="center" class="formtable">
<tr>
<td height="23" colspan="8" align="center" valign="middle" bgcolor="#FFFFFF" class="rows"><b>Cart Display</b></td>
</tr>
<tr>
<td height="66" align="left" valign="top"><table width="99%" id="suppliedtable" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="4%" height="43" align="center" valign="middle" bgcolor="#e7e6e6" class="rows"><strong>Sl.no</strong></td>
<td width="20%" align="center" valign="middle" bgcolor="#e7e6e6" class="rows"><strong>Product Name</strong></strong></td>
<td width="20%" align="center" valign="middle" bgcolor="#e7e6e6" class="rows"><strong>Barcode</strong></td>
<td width="8%" align="center" valign="middle" bgcolor="#e7e6e6" class="rows"><strong>Quantity</strong></strong></td>
<td width="8%" align="center" valign="middle" bgcolor="#e7e6e6" class="rows"><strong>Select</strong></strong></td>
</tr>
<?
$i=0;
if($productName->num_rows() >0){
foreach($productName->result() as $row ){
$i++;
?>
<tr>
<td align="left" valign="middle" bgcolor="#FFFFFF" class="rows"><?=$i;?></td>
<td align="left" valign="middle" bgcolor="#FFFFFF" class="rows"><?=$row->product_name?></td>
<input type="hidden" name="product_name<?=$i?>" id="product_name<?=$i?>" class="button" value="<?=$row ->product_name;?>"/>
<td align="left" valign="middle" bgcolor="#FFFFFF" class="rows"><?=$row->barcode?></td>
<input type="hidden" name="barcode<?=$i?>" id="barcode<?=$i?>" class="button" value="<?=$row ->barcode;?>"/>
<td align="left" valign="middle" bgcolor="#FFFFFF" class="rows"><form><input type="text" name="Quantity<?=$i;?>" id="Quantity<?=$i;?>" /></form></td>
<td align="left" valign="middle" bgcolor="#FFFFFF" class="rows"><form>
<input type="checkbox" name="status<?=$i;?>" id="status<?=$i;?>" value="yes" /> <br /></form></td>
</tr>
<? }}else{?>
<tr>
<td height="23" colspan="8" align="center" valign="middle" bgcolor="#FFFFFF" class="rows"><b>Selected product has not been processed yet</b></td>
</tr>
<?}?>
</table></td>
</tr>
<input type="hidden" name="numOflimit" id="numOflimit" class="button" value="<?=$i?>"/>
<tr><td><input type="hidden" name="cart1" id="cart1"></td></tr>
</table>
<form><tr><td align="center" > <button onclick="go()">Submit</button></td> </tr>
<tr> <td id="cart"> </td> </tr>
<div id="test"></div>
</form></form>
</form>
----------------------jquery code----------------------------------------------
for(k=0;k<=9000;k++)
{ //each change
$("#status"+k).change(function () {
var numOflimit = encodeURIComponent($('#numOflimit').val());
//alert(numOflimit);
for(j=0;j<=numOflimit;j++)
{
var product_name = encodeURIComponent($('#product_name'+j).val());
//alert(product_name);
var barcode = encodeURIComponent($('#barcode'+j).val());
var Quantity = encodeURIComponent($('#Quantity'+j).val());
//var unitBag = encodeURIComponent($('#unitBag'+k).val());
//var postData = $("form").serialize();
// alert(postData);
var cart=product_name + barcode + Quantity;
alert(cart);
$('#cart1').val(cart);
}
});
}
Have you got a full working example up somewhere, so we can actually try it? Debugging an undefined error in JavaScript just by looking at a code snippet is not the easiest thing in the world.
You might also want to open the JavaScript error console in Firefox and check the errors tab straight after the alert appears, as that might give you a useful pointer as to where the error is (e.g. you've forgotten to define a variable somewhere). The Firebug plugin may also help: http://getfirebug.com/
Edit: Just noticed that this seems to be a duplicate of another question:
jquery to fetch the contents from a selected row in php

Categories