I am having trouble with passing multiple variables into on jQuery function (jQuery v3.6.1)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
function takeId(newButtonId, startTime, endTime, date, note){
$('#myModal').modal('show');
try {
$('#bookingIdHidden').attr('value', newButtonId);
$('#timeStart').attr('value', startTime);
$('#timeEnd').attr('value', endTime);
$('#date').attr('value', date);
$('#note').attr('value', note);
} catch(err) {
alert(err);
}
};
For some reason this does not work (function does not run at all), however it does work when I only pass in one value and only set the value of #bookingIdHidden
This function is called using onclick() from a button, here:
<input type='button' name='edit' value='Edit' onclick="takeId($newButtonId, $startTime, $endTime, $date, $note);" id='1'>
Echo Version
echo "<td>" . "<input type='button' name='edit' value='Edit' onclick='takeId($newButtonId, $startTime, $endTime, $date, $note)' id='1'>" . "</td>";
<input type="button" name="edit" value="Edit" onclick="takeId(1," 06:00:00.0000,="" 07:00:00.0000,="" 2023-01-05,="" ,="" 0)="" id="1">
Would anyone know why?
All help will be much appreciated
First of all you are passing extra parameter while calling a function. Remove extra parameters and try. If it is still not work then try below solution
Pass parameters to function in single quotes like given below code snippet.
<input type="button" name="edit" value="Edit" onclick="takeId(1, '06:00:00.0000', '07:00:00.0000', '2023-01-05', '') id="1">
Related
guys im trying to get the user typed value inside of a tinymce editor, which already has a dynamically set value in it. the problem is im not able to get the edited values inside the editor as it returns only the dynamically pre set values when tested with alert popup. so what should i do to get the edited value inside the editor.
here is the code for the dynamically set value inside the editor:
$statusui_edit="<div type='".$updateid."' class='hidden_edit_4_session session_editor".$updateid." jumbotron'>"
. "<a href='#' type='".$updateid."' class='pull-right close_edit' title='Close without editing'>Close X</a>"
. "<input type='text' class='form-control title_s_edit title_s_".$updateid."' name='status_title' value='".html_entity_decode($title)."' placeholder='Title' >"
. "<div> </div>"
. "<textarea id='wall_edit_1' type='".$updateid."' rows='5' cols='50' class='session_edit text_value_".$updateid."' wrap='hard' placeholder='whats up ".$session_uname."'>
".html_entity_decode($data)."</textarea><br>"
. "<button style='float:right;' attrid='".$updateid."' type='a' class='btn btn-warning btn btn-large btn-lg post-s-edit'>Update</button></div>";
here is the jquery code that im using to edit the value of tinymce editor:
$(".post-s-edit").click(function(){
var attrid=$(this).attr('attrid');
var title= $(".text_s_"+attrid).val();
var data=$(".text_value_"+attrid).val();
alert(title);
alert(data);
/*$.post(
"status/update_status_ajax.php",
);*/
});
you can try this:-
tinyMCE.activeEditor.getContent();
for detail information: Click here
I have been trying for few hours now to try and get this working. However, the code is working fine but the second button just does not show on my website. Could you please help?
echo "<td><input class=button_normal type=button value=Google Renter onclick=window.window.open(href='https://www.google.co.uk/')";
echo "<input class=button_normal type=button value=Yahoo onclick=window.window.open(href='https://www.yahoo.co.uk')</td>";
You haven't added quotations to onclick, value and class. You also forgot to close the input tag.
echo "<td><input class='button_normal' type='button' value='Google Renter' onclick='window.window.open.href=\'https://www.google.co.uk/\''/>";
echo "<input class='button_normal' type='button' value='Yahoo' onclick='window.location.href=\'https://www.yahoo.co.uk\''/></td>";
What I suggest is this:
<script>
function goToYahoo() {
window.open('https://www.yahoo.co.uk');
}
function goToGoogle() {
window.open('https://www.google.co.uk');
}
</script>
<?php
echo "<td><input class='button_normal' type='button' value='Google Renter' onclick='goToGoogle()'/>";
echo "<input class='button_normal' type='button' value='Yahoo' onclick='goToYahoo()'/></td>";
?>
window.location is a property not method:
window.location(href='https://www.yahoo.co.uk')
Should be:
window.location.href='https://www.yahoo.co.uk'
Basically in your code you are missing input tag closing "/>"
echo <<<"FOOBAR"
<td>
<input class="button_normal" type="button" value="Google Renter" onclick="window.open('https://www.google.co.uk/')"/>;
<input class="button_normal" type="button" value="Yahoo" onclick="window.open('https://www.yahoo.co.uk')"/>
</td>
FOOBAR;
I work with this code:
<form method="get" name="MobileDetails">
<input name="brand" id="brand" value="<?php echo $brand;?>" type="hidden">
<input name="brid" id="brid" value="<?php echo $brandid;?>" type="hidden">
<button type="button" name="submitButton" value="get Details" onclick="getDetails()">
</form>
java script
<script type="text/javascript">
function getDetails(){
var brand = document.getElementById('brand').value;
var brandid = document.getElementById('brid').value;
document.MobileDetails.action = 'details.php?brand='+brand+'&id='+brandid;
document.MobileDetails.submit();
}
</script>
But it does not work in while loop. Whats the problem? My code is given below.
When i click on the button it do not do anything. But the code work great with out while loop given on the top.
<?php
require_once('connection.php');
$SQL= "SELECT*FROM mobile ORDER BY price ASC LIMIT 10";
$result= mysql_query($SQL);
while ($db_field = mysql_fetch_assoc($result)){
$brand=$db_field['brand'];
$id=$db_field['id'];
$model=$db_field['model'];
echo "<form method='get' name='MobileDetails'>";
echo " <input name='brand' id='brand' value='". $brand ."' type='hidden'>";
echo" <input name='brid' id='brid' value='". $id ."' type='hidden'>";
echo" <input name='mod' id='mod' value='". $model ."' type='hidden'>";
echo" <button type='button' name='submitButton' value='get Details' onclick='getDetails()'/>
</form> ";
echo "CLICK HERE";
}
?>
You're using several times the same id. Ids have to be unique.
Uou are dealing with multiple id's. The job of an ID is to be unique identifier for the element. I suggest just using
<form action="details.php" type="get">
this will do exactly what you are trying to achieve without using the function.
The thing with element ID's is that they need to be unique for the page; however, as you may see, not required for HTML to be displayed. When calling your JS function getDetails(), it grabs the element by ID but when you have multiple ID's in the page, this will fail.
So what can you do? Well, in your loop, you create a new form for each 'brand'. You can pass a reference of the form to the grabdetails and then, by NAME, grab the values from that form.
Rather than using Javascript to generate a link based on given details put in a hidden field, you should just generate the action at the PHP level.
echo "<form method='get' name='MobileDetails' action='details.php?brand=$brand&id=$brandid'>";
But since you do have hidden fields, using just action='details.php' the form will take the user to
details.php?brand={brand}&brid={id}&mod={model}
You should look into POST or making your button into a plain link rather than having a form.
I have a PHP code which generates a dynamic list inside a form like the following, note that the list is built dynamically from database:
echo '<form name="List" action="checkList.php" method="post">';
while($rows=mysqli_fetch_array($sql))
{
echo "<input type='password' name='code' id='code'>";
echo "<input type='hidden' name='SessionID' id='SessionID' value='$rows[0]' />";
echo "<input type='submit' value='Take Survey'>";
}
What I need is to POST the data corresponding to the user choice when he clicks on the button for that row to another page.
If we use hyperlinks with query strings there will be no problem as I'll receive the data from the other page using a GET request and the hyperlinks would be static when showed to the user.
Also I need to obtain the user input from a textbox which is only possible with POST request.
Simply from the other page (checkList.php) I need these data for further processing:
$SessionID=$_POST['SessionID'];
$Code=$_POST['code'];
As I have a while loop that generates the fields, I always receive the last entry form the database and not the one corresponding to the line (row) that the user chosed from the LIST.
I'm going to recommend that you clean up the names of variables so that your code can
at least tell us what it's supposed to do. It should be rare that someone looks at your code
and has a lot of trouble trying to see what you're trying to accomplish :P, ESPECIALLY when you need help with something ;]. I'm going to try some things and hope that it makes doing what you want easier to comprehend and perhaps get you your answer.
It's good to try your best to not echo large amounts of HTML unnecessarily within a script , so firstly I'm going to remove the
echos from where they are not necessary.
Secondly, I'm going to use a mysql function that returns an easier to process result.
$user = mysqli_fetch_assoc($sql)
Third, I don't know if form having a name actually does anything for the backend or frontend of php, so I'm
just going to remove some of the extra crust that you have floating around that is either invalid HTML
or just doesn't add any value to what you're trying to do as you've presented it to us.
And yes, we "note" that you're building something from the database because the code looks like it does =P.
I'm also sooo sad seeing no recommendations from the other answers in regard to coding style or anything in regard to echoing html like this :(.
<?php while($user = mysqli_fetch_assoc($sql)): ?>
<form action="checkList.php" method="post">
<input type='password' name='code' value='<?php echo $user['code'] ?>' />
<input type='hidden' name='SessionID' value='<?php echo $user['id'] //Whatever you named the field that goes here ?>' />
<input type='submit' value='Take Survey' />
</form>
<?php endwhile; ?>
i not sure this is correct
echo '<form name="List" method="post">';
while($rows=mysqli_fetch_array($result))
{
echo "<input type='password' name='code' id='code'>";
echo "<input type='button' value='Take Survey' onclick=show($rows[0])>";
echo "<br>";
}
and javascript
<script>
function show(id)
{
alert(id);
window.location="checkList.php?id="+id;
}
</script>
On checkList.php
$id=$_GET['id'];
echo $id;
You can just check in checkList.php whether $_POST['code'] exists and if exists retrieve $_POST['SessionID'] which will be generated from database. But one thing, if You have all hidden fields in one form, they all will be sent, so You need to think how to correct that - maybe seperate forms for each hidden field, submit button and maybe other POST fields.
And afterwards, You will be able to get data in the way You need - $SessionID=$_POST['SessionID'];
I suppose it is the easiest way to solve that.
You can try something like this:
while($rows=mysqli_fetch_array($sql))
{
$index = 1;
echo "<input type='password' name='code' id='code'>";
//Attach $index with SessionID
echo "<input type='hidden' name='SessionID_$index' id='SessionID' value='$rows[0]' />";
echo "<input type='submit' value='Take Survey'>";
}
On checkList.php
<?php
$num = explode('_', $_POST['SessionID']);
$num = $num[1];
//in $num you will get the number of row where you can perform action
?>
$form = 1;
while($rows=mysqli_fetch_array($sql))
{
echo '<form name="List_$form" action="checkList.php" method="post">';
echo "<input type='password' name='code' id='code_$form'>";
echo "<input type='hidden' name='SessionID' id='SessionID_$form' value='$rows[0]' />";
echo "<input type='submit' value='Take Survey'>";
echo '</form>';
$form++;
}
I have this form which allows the input of any product quantity from 1-10:
<form method='post' action='cart.php'>
<input type='number' name='quantitychange' size='2' min='1' max='10' value=".$_SESSION["itemsSelected"][$i][1].">
<input type='hidden' name='ProductID' value=".$_SESSION["itemsSelected"][$i][0].">
<input type='submit' value='Update'>
</form>
And another form (button) to display a selection of payment modes:
<form action='cart.php' method='post'>
<input type='hidden' name='next'>
<input type='submit' value='Select Payment Mode'>
</form>
What I want to happen is that when a user did not input anything (1st form), ex. null or 0, I want to display an alert box that says 'Product quantity can't be null or 0'.
Here's my code for that:
if (isset($_POST['next'])) {
if ($_POST['quantitychange']==null || $_POST['quantitychange']==0) {
?>
<script type='text/javascript'>
alert('Product quantity can't be null or 0.');
</script>
<?php
}
else {
echo "
//Payment modes here
";
}
}
The error is that even when a user inputs a quantity bet. 1 to 10, it still displays the alert message. Any help? Thank you.
By the way, the input type "number" only works in Google Chrome browser.
Use a small javascript (or jQuery) function to validate the form before posting it. Have this function throw up the alert if your condition isn't met and then return false. If the condition is met, return true, and it gets submitted.
Edited to add since this might get googled, I'll help a bit with code snippet I have used. The below example is jQuery and was used in production for a web application I made for my employees. document.form.doit.submit(); should be the pure javascript way of submitting the form.
<script type="text/javascript">
function subForm() {
// document.form.doit.submit();
if( test condition passes ) {
$('#save_order').submit();
}
}
</script>
<form id="save_order" action="oms_db.php" method="POST">
<input id="doit" type="button"
value="i am a button" onClick="subForm();">
</form>
I think you have some error in your forms. Instead of the below:
<input type='number' name='quantitychange' size='2' min='1' max='10' value=".$_SESSION["itemsSelected"][$i][1].">
<input type='hidden' name='ProductID' value=".$_SESSION["itemsSelected"][$i][0].">
you should be using something like this:
<input type='number' name='quantitychange' size='2' min='1' max='10' value="<?php echo $_SESSION["itemsSelected"][$i][1]; ?>">
<input type='hidden' name='ProductID' value="<?php echo $_SESSION["itemsSelected"][$i][0]; ?>">
The value parameters in the hidden input fields needs to be echoed from PHP. What you have now is like the value is simple strings ".$_SESSION["itemsSelected"][$i][0].".
I suggest you use
if(empty($_POST['quantitychange'])) { echo 'yourerror'; }
As it is far cleaner then your script. (http://php.net/manual/en/function.empty.php)
Update:
Also, you can't use two seperate forms like you do, your browser only posts whats between
<form>
</form>
Using only one will fix your problem.