Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
165
rated 0 times [  166] [ 1]  / answers: 1 / hits: 16132  / 11 Years ago, sun, december 29, 2013, 12:00:00

I am trying to update a database from an onClick procedure inside an anchor.



<a name=“fs1” onClick=updateArea1();></a>


I am struggling with the function for updateArea1 as I'm not really sure how I can pass the name fs1 from the anchor and update the database from a script process.



I would essentially like the database to be updated like this:
UPDATE row WHERE id = 1 WITH (name_from_anchor)



However... the variable does not HAVE to come from the name tag. It could be referenced in the parenthesis of the function like this if it's easier.



<a onClick=updateArea1(fs1);></a>


Any help would be greatly appreciated.



-- UPDATED --



LAUNCH.PHP



<!doctype html>
<html>
<head>
<meta charset=UTF-8>
<meta name=apple-mobile-web-app-capable content=yes />

<script src=includes/scripts/jquery-2.0.3.min.js></script>

<script>
function updateArea1(el) {
$.post(includes/db_update.php, $(#console).serialize());
}
</script>

</head>

<body>

<a name=fs1 onClick=updateArea1(this.name);></a>
<a name=fs2 onClick=updateArea1(this.name);></a>

</body>
</html>


DB_UPDATE.PHP



<?php

include 'db_connect.php';

$area1= mysqli_escape_String($con,$_POST[]);

$query = UPDATE previewState SET selected='.$area1.' WHERE id='1';;

mysqli_query($con,$query);

mysqli_close($con);

?>

More From » php

 Answers
24

If you pass this as argument can do:



<a name=fs1 onClick=updateArea1(this);></a>

updateArea1(el){
alert( el.name)
}

[#73499] Friday, December 27, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
toddbrandtc

Total Points: 400
Total Questions: 104
Total Answers: 90

Location: Antigua and Barbuda
Member since Wed, Aug 4, 2021
3 Years ago
;