How to code onclick

Hi, The below code produces a menu, I select an account to confirm username, etc. and want to go
to the selected “website” (a database field - http:// I’ve tried and tried but I
can’t figure out the onclick or whatever to go to the website.

<!DOCTYPE><html><head><title>lookup menu</title></head><body><center>
<form name="form" method="post" action="">
//============== check connection
{echo "Can't Connect to mySQL:".mysqli_connect_error();}
{echo "Connected to mySQL</br>";}
//This creates the drop down box
echo "<select name= 'website'>";
echo '<option value="">'.'--- Select lookup account---'.'</option>';
$query = mysqli_query($con,"SELECT website FROM lookuptbl");
$query_display = mysqli_query($con,"SELECT * FROM lookuptbl");
{echo "<option value='". $row['website']."'>".$row['website']
echo '</select>';

<input type="submit" name="submit" value="Submit"/>
$name = $_POST['website'];
$fetch="SELECT id,website, username, password, purpose, emailused,lastused,
count FROM lookuptbl WHERE website = '".$name."'";
$result = mysqli_query($con,$fetch);
{echo "Error:".(mysqli_error($con));}
//display the table
echo '<table border="1">'.'<tr>'.'<td bgcolor="#ccffff align="center">'. 'lookup menu'. '</td>'.'</tr>';
echo '<tr>'.'<td>'.'<table border="1">'.'<tr>'.'
<td bgcolor="#CFB53B align="center">'.'id'.'</td>'.'
<td bgcolor="#CFB53B align="center">'.'website'.'</td>'.'
<td bgcolor="#ccffff align="center">'.'username'.'</td>'.'
<td bgcolor="#ccffff align="center">'.'password'.'</td>'.'
<td bgcolor="#ccffff align="center">'.'purpose'. '</td>'.'
<td bgcolor="#ccffff align="center">'.'emailused'.'</td>'.'
<td bgcolor="#CFB53B align="center">'.'lastused'.'</td>'.'
<td bgcolor="#CFB53B align="center">'.'count'. '</td>'.'</tr>';
{echo ("<tr><td>$data[0]</td><td>$data[1]</td><td>$data[2]</td><td>$data[3]</td>
echo '</table>'.'</td>'.'</tr>'.'</table>';
$sql = "UPDATE lookuptbl SET lastused=NOW(), count=$count + 1 WHERE website=$website";
if ($con->query($sql) === TRUE) { echo "Record updated successfully"; }
else { echo "Error updating record: " . $con->error; }
<button onclick="myFunction()">go to website</button>
function myFunction() {
  document.getElementById("website").innerHTML = "";

I have no experience with the above code, but you could basically reproduce that behaviour using an anchor tag inside the button.
Asuming you wanna make it using the onclick event try putting this in your function:'', '_blank')

try putting some console logs to see whether the code is executing.
Also suggest you put the code on a codepen or somewhere like that so people can try it and play with it.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.