PHP - Php In Onclick
Hi!
I need help with passing php variable in onclick, can someone please correct code below? Right now the location.href is showing $match_link variable in address bar, it's not reading it. $matchlink = 'onclick="location.href=\'$match_link\';"'; I then echo HTML template... <div class="rankingrow" style="height:28px;background-color:$bg_color" $matchlink> thanks for help. Similar Tutorialshello all, I inserted a javascript event handler 'onclick' into php code. the onclick has a php variable in it that is supposed to trigger an alert when clicked. I can't figure out how to escape the php variable correctly, so I just left it at the last thing I tried, which I know is wrong. Any help is appreciated. thanks Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript"> function popUp(a) { alert(a); } </script> </head> <body> <?php $gmail ='yaaah'; echo '<p onclick=popUp(\'$gmail\')>lkjlkjlkjlkjlkjlkj</p>'; ?> </body> </html> Hi everyone, I want to know, will Javascript's onclick on button work in PHP while loop? I mean, If I out "onclick" with function inside html tag, then put html inside echo under while loop. Will JavaScript's onclick work? Like this script below:
$i = 0; while( $i < 5) { echo "<button id='btn' onclick='test()'>Hello</button>"; $i++; }
This loop will create 4 times loop with same echo with onclick, so will onclick call Javascript programming? i have this code which fetch meta tags and title
function file_get_contents_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $data = curl_exec($ch); curl_close($ch); return $data; } $html = file_get_contents_curl("http://example.com/"); //parsing begins he $doc = new DOMDocument(); @$doc->loadHTML($html); $nodes = $doc->getElementsByTagName('title'); //get and display what you need: $title = $nodes->item(0)->nodeValue; $metas = $doc->getElementsByTagName('meta'); for ($i = 0; $i < $metas->length; $i++) { $meta = $metas->item($i); if($meta->getAttribute('name') == 'description') $description = $meta->getAttribute('content'); if($meta->getAttribute('name') == 'keywords') $keywords = $meta->getAttribute('content'); } if(!title == ' ') { echo ' found a title'; }in this code you see in last i have if condition (!title==' ') its execute it when i open file i want its only run when i click the html button like <input type="button" name="Release" onclick="" value="Click "> please tell me what i do help me it is posible to make something like this? <a href="" onclick="refresh('index.php?info=1');"/>Index 1</a> <a href="" onclick="refresh('index.php?info=2');"/>Index 1</a> <a href="" onclick="refresh('index.php?info=3');"/>Index 3</a> and what code do i need to autorealod the index.php?info=(1,2,3) in my Index.php (simple php file with index.php?info=(1,2,3) include) ? This may not the best place to post this but I'm sure quite a few people here can help. I have an a tag which uses the event trigger "onClick" However when I click on this link the page refreshes. Is there anyway I can stop this? I have copied my code below. <a href=\"#\" class=\"" . $a[$i] . "\" onClick=\"locationValue('" . $a[$i] . "', '" . $_GET['search_type'] . "')\"> Hello,
I am trying to make 'onclick img' that will provide a Linux command when clicked.
I've been trying this code:
<body> <?php include("connect.php"); include('Net/SSH2.php'); *** CONNECTION TO DATABASE MYSQL CODE *** if(mysql_num_rows($result) > 0) { while($row = mysql_fetch_array($result)) { $_SESSION['logged'] = true; $ssh = new Net_SSH2('xx.xx.xx.xx'); if (!$ssh->login($info['username'], $info['password'])) { exit('Connection to Linux has failed, please try again.'); } echo '<form action="" method="GET">'; echo '<input type="image" src="start.png" width=100 height=100 name="start" />'; echo '</form>'; if(isset($_GET['start'])) { echo $ssh->setTimeout(5); echo $ssh->exec('(cd '.$info['username'].' ; nohup ./samp03svr &)'); } } } else { $_SESSION['logged'] = null; header("Location: loginfail.php"); } ?> </body>But when I clicked the image, it sends me to "loginfail.php". Please help >< I have a function in JS that i would like to pass 2 variables to. One is an int and one is a string. I am struggling to get the string part right as it needs to be wrapped in quotes. My code is : $out.="<div onclick='newTransactionLine(".$r['id'].",".$r['direction'].")' class='transactionItem btn $class d-block mb-2' data-id='".$r['id']."' >".$r['item']."<br/>£".$r['price']."</div>"; which outputs: <div onclick="newTransactionLine(1,OUT)" class="transactionItem btn btn-primary d-block mb-2" data-id="1">Adult Membership (£85)<br>£85.00</div> When i click the button that gets made, i get a reference error on the word out. I have no doubt it is very simple but i just cannot get this to work for me.
Hey guys, I was wondering if it is possible to have a value inserted into a table as someone clicks on a link (in order to count views for example)? thanks! Hi, I'm new to php and just trying to practice with some codes I have. I have a php code to delete an entry from a database, all works well but I want to try to use the 'onclick' event to prompt for confirmation. However, when I add this I end up with a blank page. Then original code was: echo('<p>' . $commenttext . '<a href="adddelete.php?deletecomment=' . $commentid . '">' . 'Delete this Comment</a></p>'); I changed it to: echo('<p>' . $commenttext . '<a href="adddelete.php?deletecomment=' . $commentid . ' onclick='return confirm('Are you SURE you want to delete this comment?')'">' . 'Delete this Comment</a></p>'); Anyone know what the problem could be, or an alternative way to get a confirmation before deleting? Thanks in advance. I have 3 images Shown below. What I want to do is add an onclick that will change another variable (lets call it $secondary). So when any one of these are clicked it will change the variable $secondary to whatever I want it to be. (hope that makes sence) <?php $main[0]="<img src='images/00.gif'>"; echo $main[0]; ?> <?php $main[1]="<img src='images/01.gif'>"; echo $main[1]; ?> <?php $main[2]="<img src='images/02.gif'>"; echo $main[2]; ?> This URL works fine: http://www.adodarts.com/calendarandresults/ This URL works fine: http://www.adodarts.com/calendarandresults/?year=2010®ion=&state= If I select 2009, it does not work: http://www.adodarts.com/calendarandresults/?year=2009®ion=&state= Here is the code: <script type="text/JavaScript"> <!-- function MM_jumpMenu(targ,selObj,restore){ //v3.0 eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'"); if (restore) selObj.selectedIndex=0; } function poptastic(url) { newwindow=window.open(url,'name','height=400,width=525,scrollbars=yes,resizable=yes'); if (window.focus) {newwindow.focus()} } function poptastic1(url) { newwindow=window.open(url,'name','height=550,width=650,scrollbars=yes,resizable=yes'); if (window.focus) {newwindow.focus()} } //--> </script> <div align=center style="background-color:#66CCFF; font-size:18px; font-weight:bolder;"><a href="http://www.adodarts.com/files/ADOPlayoffInformation2010.pdf" target="_blank">Click here for 2010 ADO Playoff Information</a></div> <br> <div align=center style="background-color:#FFCC66; font-size:18px; font-weight:bolder;">Click below for 2010 ADO Regional Results</div> <div align=center style="background-color:#FFCC66; font-size:14px; font-weight:bolder;"><a href="2010-masters">MASTERS</a> - <a href="2010-all-stars">ALL-STARS</a> - <a href="2010-us-team"">US Team</a> - <a href="2010-cricket">Cricket</a></div> <table height=30> <tr><td> </td></td> </table> <form name="form1"> <table align=center> <tr> <td><select name="year" > <option value="">Year</option> <option value="2011">2011</option> <option value="2010">2010</option> <option value="2009">2009</option> </select> </td><td><select name="region"> <option value="">Region</option> <option value="">All Regions</option> <option value="1-1">Region 1-1</option> <option value="1-2">Region 1-2</option> <option value="1-3">Region 1-3</option> <option value="1-4">Region 1-4</option> <option value="1-5">Region 1-5</option> <option value="2-1">Region 2-1</option> <option value="2-2">Region 2-2</option> <option value="2-3">Region 2-3</option> <option value="2-4">Region 2-4</option> <option value="2-5">Region 2-5</option> <option value="3-1">Region 3-1</option> <option value="3-2">Region 3-2</option> <option value="3-3">Region 3-3</option> <option value="3-4">Region 3-4</option> <option value="3-5">Region 3-5</option> <option value="4-1">Region 4-1</option> <option value="4-2">Region 4-2</option> <option value="4-3">Region 4-3</option> <option value="4-4">Region 4-4</option> <option value="4-5">Region 4-5</option> <option value="4-6">Region 4-6</option> <option value="5-1">Region 5-1</option> <option value="5-2">Region 5-2</option> <option value="5-3">Region 5-3</option> <option value="5-4">Region 5-4</option> <option value="5-5">Region 5-5</option> <option value="6-1">Region 6-1</option> <option value="6-2">Region 6-2</option> <option value="6-3">Region 6-3</option> <option value="6-4">Region 6-4</option> <option value="6-5">Region 6-5</option> </select> </td><td><select name="state"> <option value="">State</option> <option value="">All States</option> <option value="AL">Alabama</option> <option value="AK">Alaska</option> <option value="AZ">Arizona</option> <option value="AR">Arkansas</option> <option value="CA">California</option> <option value="CO">Colorado</option> <option value="CT">Connectictut</option> <option value="DE">Delaware</option> <option value="FL">Florida</option> <option value="GA">Georgia</option> <option value="HI">Hawaii</option> <option value="ID">Idaho</option> <option value="IL">Illinois</option> <option value="IN">Indiana</option> <option value="IA">Iowa</option> <option value="KS">Kansas</option> <option value="KY">Ketucky</option> <option value="LA">Louisiana</option> <option value="ME">Maine</option> <option value="MD">Maryland</option> <option value="MA">Massachusetts</option> <option value="MI">Michigan</option> <option value="MN">Minnesota</option> <option value="MS">Mississippi</option> <option value="MO">Missouri</option> <option value="MT">Montana</option> <option value="NE">Nebraska</option> <option value="NV">Nevada</option> <option value="NH">New Hampshire</option> <option value="NJ">New Jersey</option> <option value="NM">New Mexico</option> <option value="NY">New York</option> <option value="NC">North Carolina</option> <option value="ND">North Dakota</option> <option value="OH">Ohio</option> <option value="OK">Oklahoma</option> <option value="OR">Oregon</option> <option value="PA">Pennsylvania</option> <option value="RI">Rhode Island</option> <option value="SC">South Carolina</option> <option value="SD">South Dakota</option> <option value="TN">Tennessee</option> <option value="TX">Texas</option> <option value="UT">Utah</option> <option value="VT">Vermont</option> <option value="VA">Virginia</option> <option value="WA">Washington</option> <option value="WV">West virginia</option> <option value="WI">Wisconsin</option> <option value="WY">Wyoming</option> </select> </td><td> <input type="submit" value="Filter" onClick="MM_jumpMenu('parent',this,0)"> </td></tr> </table> <strong><em>*Note: Unsanctioned tournaments will not have links</em></strong> </form> <?php $year = $_GET['year']; $region = $_GET['region']; $state = $_GET['state']; if($year == 0) { $year = '2010'; } $dbh=mysql_connect ("localhost", "database", "password") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("adodarts_TournamentCalendar"); $y = "`sdate` >= '2010-01-01' AND `sdate` <= '2010-12-31'"; $r = ""; $s = ""; if($year == 2009) { $y = "`sdate` >= '2009-01-01' AND `sdate` <= '2009-12-31'"; } if($region != "") { $r = " and `region` = '" . $region . "'"; } if($state != "") { $s = " and `state` = '" . $state . "'"; } $query = "SELECT * FROM `ADOSanctionedTournaments` WHERE " . $y . $r . $s . " ORDER BY `sdate`"; $result = mysql_query($query,$dbh) or die(mysql_error()); ?> <table width=100% align=center> <?php while($row = mysql_fetch_array($result)) { $rrn = $row[rrn]; if(substr($row['sdate'],5,2) == 1) { $alphamonth = 'January'; } elseif(substr($row['sdate'],5,2) == 2) { $alphamonth = 'February'; } elseif(substr($row['sdate'],5,2) == 3) { $alphamonth = 'March'; } elseif(substr($row['sdate'],5,2) == 4) { $alphamonth = 'April'; } elseif(substr($row['sdate'],5,2) == 5) { $alphamonth = 'May'; } elseif(substr($row['sdate'],5,2) == 6) { $alphamonth = 'June'; } elseif(substr($row['sdate'],5,2) == 7) { $alphamonth = 'July'; } elseif(substr($row['sdate'],5,2) == 8) { $alphamonth = 'August'; } elseif(substr($row['sdate'],5,2) == 9) { $alphamonth = 'September'; } elseif(substr($row['sdate'],5,2) == 10) { $alphamonth = 'October'; } elseif(substr($row['sdate'],5,2) == 11) { $alphamonth = 'November'; } elseif(substr($row['sdate'],5,2) == 12) { $alphamonth = 'December'; } if($alphamonth != $alphamonthhold) { echo "<tr><td colspan=5 align=center bgcolor=#CCCCCC>"; echo '<div style="color:#0000CC; font-size:14px; font-weight:bold">' . $alphamonth . '</div>'; echo "</td></tr>"; } echo "<tr><td align=center>"; echo substr($row['sdate'],8,2); if(substr($row['sdate'],8,2) != substr($row['edate'],8,2)) { echo "-" . substr($row['edate'],8,2) . " "; } echo "</td><td>"; if($row['filename'] != "" & $row['tournamentdirector'] == ""){ echo "<a href=\"javascript:poptastic1('http://www.adodarts.com/calendar/tournament.php?rrn=$rrn');\">"; echo $row['tournament']; echo "</a>"; } elseif($row['filename'] != "" & $row['tournamentdirector'] != "" & $row['paymentreceived'] == "Y" & $row['adoapproved'] == "Y"){ echo "<a href=\"javascript:poptastic1('http://www.adodarts.com/calendar/tournament.php?rrn=$rrn');\">"; echo $row['tournament']; echo "</a>"; } elseif($row['filename'] == "" & $row['tournamentdirector'] == "" & $row['paymentreceived'] == "Y" & $row['adoapproved'] == "Y"){ echo "<a href=\"javascript:poptastic1('http://www.adodarts.com/calendar/tournament.php?rrn=$rrn');\">"; echo $row['tournament']; echo "</a>"; } else { echo $row['tournament']; } echo "<font color=white>" . $row[rrn] . "</font>"; echo "</td><td align=right>"; echo "$" . number_format($row['purse']); echo "</td><td>"; echo $row['state']; echo "</td><td>"; if($row['results'] != "Y") { echo " "; } else { echo "<a href=\"javascript:poptastic1('http://www.adodarts.com/calendar/results.php?rrn=$rrn&year=$year');\">results</a>"; } echo "</td>"; $alphamonthhold = $alphamonth; } echo "</tr></table>"; ?> </td> </tr> </table> Amazingly, PHP Coding Help is not the place to ask JavaScript questions. Mind blown. This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=332796.0 Hello, When a user clicks a Submit button on my page, I'm using an onClick event to essentially just disable the button and change the message to 'Saving'. However, when I add the onClick code, the form no longer posts using PHP. The button does indeed change but the postback never occurs. Is there something extra I need to add or do? Thank you!! This is my submit button: Code: [Select] <input type="submit" id="submit" value="Save Changes" onclick="this.disabled=true; this.value='Saving'">|<a href="/">Cancel</a> Then I have the normal PHP stuff for postback which isn't firing.... Code: [Select] //IF POSTBACK if ($_SERVER['REQUEST_METHOD'] == 'POST') { //DO STUFF HERE } Hi I have a queries to display data in my template file, and i encountered problem in onclick EMP_ID here is my query: Code: [Select] <?php include 'config.php'; $currentEmpID = $_SESSION['empID']; $sql = "SELECT em.EMP_ID, s.EMP_NO, s.SSSLoan, s.SSSAmor FROM $PAYROLL.sssloan s, $ADODB_DB.employment em WHERE em.EMP_NO= s.EMP_NO AND em.EMP_ID = '$currentEmpID'"; $rsloan = $conn2->Execute($sql); $LOAN = trim($rsloan->fields['SSSLoan']); $AMOR = trim($rsloan->fields['SSSAmor']); $smarty->assign('LOAN', $LOAN); $smarty->assign('AMOR', $AMOR); $sql = "SELECT s.EMP_NO, p.EMP_ID, p.SSS, CONCAT(LNAME, ', ', FNAME, ' ', MI, '.') AS FULLNAME, s.SSSLoan, s.SSSAmor, s.DATE_PROCESS FROM $ADODB_DB.PERSONAL p, $ADODB_DB.employment em, $PAYROLL.sssloan s WHERE s.EMP_NO = em.EMP_NO AND p.EMP_ID = '$currentEmpID' AND em.EMP_ID = '$currentEmpID'"; $rs = $conn2->GetAll($sql); $smarty->assign('getsss', $rs); ?> and here is the template code: Code: [Select] // this data will change if the EMP_ID was click <input type="text" name="LOAN" value="{$LOAN}" size="9"> <input type="text" name="AMOR" value="{$AMOR}" size="9"> {section name=att loop=$getsss} <tr> <td colspan="4" style="background: #e2e2e2" readonly="readonly">{$getsss[att].SSS}</td> <td colspan="4" style="background: #e2e2e2" readonly="readonly" onclick="changeEmployee1('{$getsss[att].EMP_ID}')">{$getsss[att].EMP_NO}</td> <!--<td colspan="4" style="background: #e2e2e2" readonly="readonly"><a href="SSSgetdata.php?queryEmpID={$getsss[att].EMP_ID}">{$getsss[att].EMP_NO}</td> --> <td colspan="15" style="background: #e2e2e2" readonly="readonly">{$getsss[att].FULLNAME}</td> <td colspan="4" style="background: #e2e2e2" readonly="readonly">{$getsss[att].SSSLoan}</td> <td colspan="4" style="background: #e2e2e2" readonly="readonly">{$getsss[att].SSSAmor}</td> <td colspan="4" style="background: #e2e2e2" readonly="readonly">{$getsss[att].DATE_PROCESS}</td> </tr> {sectionelse} <tr><td colspan="1">No DATA</td></tr> {/section} My problem is in onclick,the data loan and amor was not change when i click EMP_ID. Thank you When I click on this span I want it to alert the ID if the span...
<span id='" . $thisid . "' onClick='likeThis()'><img src='https://cdn1.iconfinder.com/data/icons/nuvola2/32x32/apps/amor.png'>Like</center></span> <script> function likeThis(){ var lb = $(this).attr('id'); alert(lb) } </script>However, it currently just says 'undefined'. What's wrong? Thanks, This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=308673.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=358574.0 Hello everybody There is one word here that I dont get to include the right way, I think because of the issue of single and double quotes. When I replace the variable by its value, it works me alright, but since I have to include this PHP variable ($user) within the onclick JS function, it is problematic. Code: [Select] <?php echo ' <form> <input type="checkbox" name="asset" value="" onclick="getLoggedInUser($user) " /> I am potentially interested in this product service<br /> <div id="txtHint"><b>Note:</b></div> </form> '; By the way, I cant believe the verification code to submit the text. It took me 2 minutes to figure out what they were talking about John, George, Paul, and I had no idea what the hell that was, when I casually thought of the Beatles. so Ringo. I hate that rubbish music. Next time I get verification code like that I go elsewhere. I have been messing with this for a few hours, and I cannot get this to work with my click. On the first example, the php runs regardless of click or not - basically when the page loads it runs... And the second, I cannot figure out how to store the while loop results in a variable to pass to the page.. I would prefer to use my first method as it's much cleaner and less code. IS this even possible? Basically I just want to run my function ONLY when the button is clicked. <a href="" onCLick="<?php myFunction(); ?>"/>Click to run function</a> OR <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> <input type="hidden" name="myFunctionRun" value=""/> <input type="submit" value="Run Function"> </form> Hello, What I am looking to do is have a series of buttons laid out and when the user 'onClick', a table from my MySQL database will load into a scrollable textbox within the same webpage. I figure I need to go about this using AJAX, which unfortunately I have basically no experience in. For example purposes here is what I have going: This php code basically just displays the table we want to tie the button click to. Code: [Select] <?php include("connect.php"); //Query of facebook database $facebook = mysql_query("SELECT * FROM facebook") or die(mysql_error()); //Output results if(!$facebook) { echo "There was an error running the query: " . mysql_error(); } elseif(!mysql_num_rows($facebook)) { echo "No results returned"; } else { $header = false; echo "<table border='1'>\n"; while($row = mysql_fetch_assoc($facebook)) { if(!$header) { echo "<tr>\n"; foreach($row as $header => $value) { echo "<th>{$header}</th>\n"; } echo "</tr>\n"; } echo "<tr>\n"; foreach($row as $value) { echo "<th>{$value}</th>\n"; } echo "</tr>\n"; } echo "</table>\n"; } mysql_close(); ?> I'd really like to make this as easy as possible. After doing research, I figured that just Javascript would not be enough because it is client-side. It would be great if someone could point me in the right direction. Thanks in advance to anyone who replies. |