Passing ID value in autocomplete in Scriptaculous - php

I have the scriptaculous autocompleter working. It pops up the data and I can select it, but it does not transfer the ID number in the form I'm using. I just cannot get the ID number. I can show the ID number on the screen using the following command:
alert (li.id);
I have used the following but no luck:
document.getElementById('inv_id').value=li.id;
and
$("#inv_id").val(li.id);
How do I pass that ID number to a value in the form? Here is the form code...
<form action="page2.php" method="post" name="Add_Form">
<input type="hidden" name="inv_id" value="0">
<input type="text" id="autocomplete" name="autocomplete_parameter"/>
<div id="autocomplete_choices" class="autocomplete"></div>
</form>
<script type="text/javascript">
new Ajax.Autocompleter("autocomplete", "autocomplete_choices", "ajax_inv.php", {
afterUpdateElement : getSelectedId
});
function getSelectedId(text, li) {
alert (li.id);
document.getElementById('inv_id').value=li.id;
or
$("#inv_id").val(li.id);
}
</script>

Where is the inv_id field? Make it a hidden input if you don't have it existing already, then document.getElementById('inv_id').value=li.id; should work

Related

Get form attribute value with PHP

Is there a way to get submitted form's attribute value using PHP, when the submit button is clicked?
I have a form which has attribute data-id: someid, I need to get this value.
There is no direct way to get the data attribute value in PHP.
You have to first get data-attribute, set this value to hidden field and then use PHP to get it.
If You Wants Data id on submit
$(document).ready(function(){
$('#formid').on('submit', function(){
var id = $(this).data("id")
alert(id);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="" method="POST" name="myformName" id="formid" data-id="someid">
<input type="submit" name="submit">
</form>
You can achieve this in php with two ways:
1. Either pass your 'someid' in input with hidden type
<input type="hidden" name="data-id" value="someid" />
2. Just pass your 'someid' in action attribute
<form name="" action="filename.php?data-id=someid">

Value Checkbox Inside modal

i'm trying to do a system to check if the member attended to the meeting.
I will check it using his ID, so, i a form to input his ID(it will be read by a bar code reader that the id will be the bar code, everything will be in a card), but if the member forget his card, should have another way to find his ID, so i'm using a modal open a form, so can find his name and pass his ID to the form.
On the modal, i'm using ajax to get dinamically his name (and his id on a checkbox), it works properly, but i cant take the checkbox value and pass it into the ID FORM.
Thats my code.
<form method="post" enctype="multipart/form-data" id="attendedForm" name="formPresenca">
<fieldset>
<label>
<span>ID</span>
<input type="text" name="id" id="alvo" />
</label>
<input type="hidden" name="acao" value="enviar" />
Seach Manually </fieldset>
</form>
JS:
$(function(){
$("a#popup").click(function(){
$.modal('<form method="post" enctype="multipart/form-data"><fieldset><label><span>Name</span><input type="text" name="Name" id="id" /></label></fieldset><div id="recebe_dados"></div></form>', {
overlayId: 'contact-overlay'
});
$("#id").on('keyup', function(){
var nome = $(this).val();
$.post("../scripts/get-name.php",
{name:name},
function(value){
$("#get_data").html(value);
});
//Dont shows me anything on the console.
$("#Checkbox").click(function(){
console.log($('#Checkbox:checked').val());
});
});
});
});
Get-value.php
$get = $_POST['nome'];
$mysql = mysql_query("SELECT id, name FROM members WHERE name LIKE '%$get%'");
while($res = mysql_fetch_array($mysql)){
echo '<input type="checkbox" name="id" value="'.$res['id'].'" id="Checkbox">'.$res['nome'];
}
I'm using Simple modal.
Since your while loop could possibly create duplicate IDs -- invalid HTML -- use the following instead:
$(document).on("click", ".Checkbox", function(){
console.log( this.value );
});
And:
echo '<input type="checkbox" name="id" value="'.$res['id'].'" class="Checkbox">'.$res['nome'];
And, this should be outside the keyup callback but inside DOM ready.

How submit a form from JQuery function without ID

I have this form, but this form inside PHP foreach function that gives the value from database, so I can't give the form id because redundancy will happened. And when click on any star in stars rating it will do as a submit, go to function so in the function I want to submit the form without id how?
<form class="watching-us-reating-form" name="swatching-us-reating-form" action=" method="get">
<input type="hidden" name="watchlist_id" value="<?php echo $fundAndUserWatchingThem['contactId']?>">
<!-- This hidden field used to save the value of the rating before submit -->
<input type="text" name="priority" class="watching-us-reating-value">
<!-- This DIV to contain the stars rating -->
<div class="watching-us-rating-div" data-score="<?php echo $flag; ?>" data-number="<?php echo $numberOfStars; ?>"></div>
</form>
You can use closest() to get the form element related to the clicked star rating:
$('.watching-us-rating-div').click(function() {
$(this).closest('form').submit();
});
Also, your form tag is missing an action - is that an error in your example?

can i submit a form without submit button or without hitting enter?

Can I submit value of <select> in php form without having submit button?
In my html/php code I am using two form or we can say two <select> as you can see in coding. In the second <select>(sub category) I want to use value of first <select>(main category) so that it can show me sub category of main <select>. but I am getting confused, how to do this on a single page without using js.
See my code:
<body>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
main course name <select name ="bcate" ><option value=''>choose</option><?php $auth->cmaster_array(); ?></select>
</form>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
sub course name <select name ="sbcate" ><option value=''>select sub course</option><?php $auth->clmaster_array($frsbct); ?></select>
section name <input type="text" name="cname" required/>
remarks <input type="text" name="remarks" required/>
<input type="submit" name="section_master" value="Submit">
</form>
</body>
The thing you've asked that , You need value of first select input for second input values.
You can do this only by using jQuery without submitting form.
write change event of first select input box.
then send data to your server by jQuery ajax.
and then fill the second input box received from ajax
Code :
// To get value of select box
$('#select_box_id').change(function()
{
var select_box_one_value = $(this).val();
});
$.ajax
({
type: "POST",
url: HOST + "/path/to_your_controller_function",
data: 'data_of_select_box='+select_box_one_value,
cache: false,
success: function(msg)
{
}
});
using this , your controller will get the value of select box value and then return data from there , and you will receive that data in msg variable.
You can submit the form using javascript.
You can use this code to submit the form
document.getElementById("[ur form id should be here]").submit();
You can use following code
<form id="jsform" action="whatever you want">
// input fields
</form>
<script type="text/javascript">
document.getElementById('jsform').submit();
</script>

Trouble passing slider value to php mail script

I want to email the value of the slider along with some things they entered into my form to my php email script. This is how the form looks that will pass data to the POST method of mailer.php:
<form method="POST" action="mailer.php">
Name:
<input type="text" name="name" size="19"><br>
<br>
E-Mail:
<input type="text" name="email" size="19"><br>
<input type="hidden" name="slider_value" size="19" value=document.getElementById('sliderValue').value><br>
<br>
<input type="submit" value="Submit" name="submit">
</form>
document.getElementById('sliderValue').value is the call I make to get the value of the slider but when I pass this to the value of my hidden input slider_value I get back "document.getElementById('sliderValue').value" in the email that is sent by my php script. How would I pass the value instead?
document.getElementById is a Javascript function. It probably won't do what you want it to unless you put it in a place where Javascript is accepted.
One way to pass the slider value is by putting the sliderValue element in the form that you are submitting.
If that is not an option, you can set the value of the slider_value element with Javascript. Either set an onsubmit attribute to the form like this:
<form method="POST" action="mailer.php"
onsubmit="this.slider_value.value = document.getElementById('sliderValue').value">
or add an event listener to do it:
var form = document.forms[0]; //this may need to be changed depending on your form
function addSliderValue() {
this.slider_value.value = document.getElementById('sliderValue').value;
}
if (form.addEventListener) { //most browsers
form.addEventListener("submit", addSliderValue, false);
} else if (form.attachEvent) { //IE
form.onsubmit = addSliderValue;
}
Bind a function to the sliders "onSlide/onChange/whatever it's called" event that will update the hidden input field with the slider value. Also set the input value to the initial slider value on slider init. That should do the trick.

Categories