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 commit 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" />
button 1
button 2
button 3
</form>
tested - working ok. thnks for your help
Add 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" />
button 1
button 2
button 3
Or get the value from $_GET and skip the JavaScript:
button 1
button 2
button 3
use jQuery
$('#anchorid').click(function(){
$.post('self.php',{data:'1'},function(){
});
});
Related
I have a submit button named "details:, and a table which had radio buttons in each rows.
On selecting radio button and then clicking on my details button I want a popup to appear.
I have used something like this: I am not sure if the code I tried is really pathetic, but plz help me.
The form I used is GET.
This is my radio button:
<input type="radio" name="ID" value="<?php echo $id; ?>" class="radioValue" />
This is my submit button:
<input type="submit" name="details1" value="Details" id="btndetails" class="btn" />
<div id="notice">
<div class="pop">
<?php
if(isset($_GET['details1']))
{
if(isset($_GET['ID']))
{
$n=$_GET['ID'];
echo$n;
//do some sql queries with the id
}
else echo"Fail";
}
?>
</div>
</div>
I have used jquery to ensure the clicks:
(function($)
{
$(function()
{
$('#btndetails').bind('click', function(e)
{
// Prevents the default action to be triggered.
if($('.radioValue').is(':checked'))
{
e.preventDefault();
$("#notice").css("display", "block");
}
else
{
<?php echo"Please select the radio button";?>');
}
});
});
})(jQuery);
the div notice is display:none;
Currently on clicking the radio button + details button i am getting a popup with msg "fail". How can I get my radio button value in the pop up? Is my method wrong? I need to get the radio value in php so that i can use it to retrieve my DB.
I dont want to use any plugins for popups. I want it only by using php,html, css .
Please help me.
This might be your problem:
<input type="submit" name="details1" value="Details" id="btndetails" class="btn" />
<div id="notice">
<div class="pop">
<?php
if(isset($_GET['details1']))
{
if(isset($_GET['ID']))
{
$n=$_GET['ID'];
echo$n;
//do some sql queries with the id
}
else echo"Fail";
}
?> // the first problem I found is here
</div>
</div>
also check your URL are you getting id parameter in query string
There is demo Demo link showing how JQWidget jqxcombobox is working with form submission. But if we look the demo closely we can see the results are changing when we use mouse or keyboard.
For example Alfreds Futterkiste is the Display Member and value is Maria Anders.
We will get the correct value (Maria Andres) when we submit the form using Mouse click, if we use the keyboard we get the same Display-member value Alfreds Futterkiste.
I think if i can add a hidden text box with below code then it may work.
Bind to the change by type: jqxComboBox.
$('#jqxComboBox').on('change', function (event)
{
var args = event.args;
if (args) {
// index represents the item's index.
var index = args.index;
var item = args.item;
// get item's label and value.
var label = item.label;
var value = item.value;
}
});
But how I populate the hidden text box with the above function...
Thanks.
I found the answer myself :)
I found a small solution for this....
1. Create a hidden field to store the value of the combobox
2. Use event.args.item.value to change the value of the hidden field.
// trigger the select event.
$("#combobox").on('select', function (event) {
var elem = document.getElementById("mytext");
elem.value = event.args.item.value;
in Body
<form class="form" id="form" target="form-iframe" method="post" action="echo.php" style="font-size: 13px; font-family: Verdana; width: 650px;">
<div name="list" id="combobox">
<input name="productvalue" type="hidden" id="mytext">
<input style="margin-top: 10px;" type="submit" value="Submit" id="sendButton" />
</form>
echo.php
<?php
echo "Wrong Data =";
echo $_POST["list"];
echo "<br />";
echo "Value through hidden feild =";
echo $_POST["productvalue"];
?>
hope this will work for someone :)
I'm creating an employee scheduler application. I want to create a button to change the calendar view to next or previous month view. But the problem is, when I click the button, the calendar changed, but the employee which has been selected to be viewed on calendar is going back to default.
I have this button in my php file:
<input type="submit" id="month-next" value="Next Month">
and I have created jquery for my button:
$('input#month-next').click(function(id){
if(month==12){
++year;
month=0;
}
++month;
$('div#month-data').load('scheduler/ajax/calendar.php?month='+month+'&year='+year+'&empid='+id);
});
so, how can I pass a my 'empid' value to my jquery function from the php page?
If your jquery in same php page you can use
$('input#month-next').click(function(){
var id = '<?php echo $empid ?>';
//your remaining code
});
If your jquery at another place you need to pass as parameter in function call:
<input type="button" id="month-next" value="Next Month" onclick="monthNext('<?php echo $empid; ?>');" >
Use a function instead of click event as above:
function monthNext(id)
{
if(month==12)
{
++year;
month=0;
}
++month;
$('div#month-data').load('scheduler/ajax/calendar.php?month='+month+'&year='+year+'&empid='+id);
}
Use button instead of input type=submit because submit will reload page.
With HTML 5 you can use data attributes.
<input type="submit" id="month-next" value="Next Month" data-empid="5">
JS:
$('input#month-next').click(function(){
id = $(this).data("empid");
// rest of your code
}
take a hidden field where you shore the employee id and after click on the button get that hidden field value like this
$('#button').click(function(){
emp_id = $('#emp_id').val();
// rest of your code
}
I have a page with three buttons and I'd like to be able to "remember" which button was pressed on a later page. The sequence of events goes something like this:
page1.html: "Please click a button." BUTTON 1, BUTTON 2, BUTTON 3
page2.html: "Thanks for clicking a button. click for next page."
page3.html: "You selected BUTTON (x) from page 1."
I'm not sure how to go about this. Any help will be much appreciated.
Use cookies.
PHP:
setcookie(name,value,expiration);
I think you are looking for a tutorial on how to doing this, a great website to get started is w3schools
You can also use a form on each page and use hidden inputs to remember anything you want from a previous page, by using a little bit of javascript. Here is the principle (untested), modify for your own case:
<form name='session_form' action='' method='POST'>
<input type='hidden' name='button_name' value=''>
</form>
<input type='button' name='button1' value='BUTTON 1' onClick='go(this);'>
<input type='button' name='button2' value='BUTTON 2' onClick='go(this);'>
<input type='button' name='button3' value='BUTTON 3' onClick='go(this);'>
<script type='text/javascript'>
function go(button) {
var f = document.forms.form_session;
var bname = button.name;
f.button_name.value = bname;
f.action = 'page' + bname[-1] + '.php';
f.submit();
}
// or if you have loaded jQuery, drop the `onClick` attribute and use something like this:
$('input[type=button]').click(function(e) {
var bname = $(this).attr('name');
$('input[name=button_name]').val(bname);
var action = 'page' + bname[-1] + '.php';
$('form[name=session_form]').attr('action', action).submit();
});
</script>
In PHP (server-side) you can then read the name of the clicked button using $_POST["button_name"].
<form action="page.php" method="post">
<input type="text" name="some_text" />
<input type="submit" name="some_submit" /
</form>
I want to submit this form by pressing defined keyboard button. I wonder how to do it. If it was just an <a> element it would be simple - I would just change window.location value after handling keypress event. But there is some data to send and I have no idea how to solve this.
You can create an event handler for a key press event, then submit the form using its submit() method to pass all the form data to the recipient page "page.php".
Using jQuery, this is trivial:
<form id="myForm" action="page.php" method="post">
<input type="text" name="some_text" />
<input type="submit" name="some_submit" />
</form>
<script type="text/javascript">
$('#myForm").keyDown(function(e){
if(e.which == 13) // When key pressed is "Enter" key.
$('#myForm').submit();
});
</script>
Read Javascript Madness: Keyboard Events for more information on interpreting keyboard events.
The data will be passed automatically as a result of form.submit()
Give a name to the form
<form name="myform" action="page.php" method="post">
After handling key press event do
document.myform.submit()
which will basically submit the form. If you want to add more parameters to it add those as hidden elements inside form.
For an example of key press handling, see http://dev.kanngard.net/Permalinks/ID_20050426091851.html - it submits a form if key 13 (Enter) is pressed, but can be modified to any other key.
In general: register a function to be called on KeyDown event, inside the function, check which key was pressed; if needed, submit() your form.
I'm in trouble:
function action(button) {
if ($('a.'+button+':visible').length > 0) {
if ($('a.'+button+':visible').attr('class') == button || $('a.'+button+':visible').attr('class') == 'rotate '+button) {
var adr = $('a.'+button+':visible').attr('href');
window.location = adr;
}
if ($('a.'+button+':visible').attr('class') != button) {
$('a.'+button+':visible').click();
}
}
if ($('input.'+button+':visible').length > 0) {
$('#form').submit();
}
}
Where variable 'button' is button's classname and #form is form's id. By clicking submit it works normally, but it doesn't work by keyboard event.