I call some links (opening table in the div) in the form
<A HREF="#1" onClick = ?????>button 1<A>
<A HREF="#2" onClick = ?????>button 2<A>
<A HREF="#3" onClick = ?????>button 3<A>
I would like through the onClick function to send data (numbers: 1, 2, 3) and receive it in PHP in the same document. I guess I have to mit to this form. How to do it?
EDIT -------------------------------------
I try the @gilly3 way
<script language="JavaScript">
function submitValue (n) {
var f = document.forms.myform_1;
f.myNumber.value = n;
f.submit();
}
</script>
<?php
global $PHP_SELF;
echo "<form action='". htmlentities($PHP_SELF)."' method=\"POST\" id=\"myform_1\">";
?>
<input type="hidden" name="myNumber" />
<a href="#1" onclick="submitValue(1)">button 1</a>
<a href="#2" onclick="submitValue(2)">button 2</a>
<a href="#3" onclick="submitValue(3)">button 3</a>
</form>
tested - working ok. thnks for your help
I call some links (opening table in the div) in the form
<A HREF="#1" onClick = ?????>button 1<A>
<A HREF="#2" onClick = ?????>button 2<A>
<A HREF="#3" onClick = ?????>button 3<A>
I would like through the onClick function to send data (numbers: 1, 2, 3) and receive it in PHP in the same document. I guess I have to mit to this form. How to do it?
EDIT -------------------------------------
I try the @gilly3 way
<script language="JavaScript">
function submitValue (n) {
var f = document.forms.myform_1;
f.myNumber.value = n;
f.submit();
}
</script>
<?php
global $PHP_SELF;
echo "<form action='". htmlentities($PHP_SELF)."' method=\"POST\" id=\"myform_1\">";
?>
<input type="hidden" name="myNumber" />
<a href="#1" onclick="submitValue(1)">button 1</a>
<a href="#2" onclick="submitValue(2)">button 2</a>
<a href="#3" onclick="submitValue(3)">button 3</a>
</form>
tested - working ok. thnks for your help
Share Improve this question edited Nov 18, 2011 at 21:59 Andrew asked Nov 18, 2011 at 21:07 AndrewAndrew 2331 gold badge3 silver badges10 bronze badges 2- 1 Basically you want to tell the server which of those 3 links was clicked on? – Marc B Commented Nov 18, 2011 at 21:10
- Basically - yes yes yes :)) I have one long 7 scripts (one for every day of the week) at one php file. I think to reduce it to one script but I must inform php file about which day (1,2,3,4,5,6,7) we are tolking. – Andrew Commented Nov 18, 2011 at 21:16
2 Answers
Reset to default 4Add hidden fields to your form. In your click handler, write whatever value you want to the hidden fields and call form.submit()
.
function submitValue (n) {
var f = document.forms.myForm;
f.myNumber.value = n;
f.submit();
}
Use it like this:
<input type="hidden" name="myNumber" />
<a href="#1" onclick="submitValue(1)">button 1</a>
<a href="#2" onclick="submitValue(2)">button 2</a>
<a href="#3" onclick="submitValue(3)">button 3</a>
Or get the value from $_GET
and skip the JavaScript:
<a href="?day=1">button 1</a>
<a href="?day=2">button 2</a>
<a href="?day=3">button 3</a>
use jQuery
$('#anchorid').click(function(){
$.post('self.php',{data:'1'},function(){
});
});