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;
Related
I have tried:
<input disabled='disabled'
checked='checked'
type='checkbox'
name='checkTema[]'
value=".$cat->cat_ID."> ".$cat->name."<br>"
But that won't pick up the value when I send the form
UPDATE
Thanks to a comment I've got a helping answer from another SO question, yet I am not sure how I should be applying the trick, tried the following but not sending the value
echo "<input type='hidden' name='checkTema[]' value='1' >";
echo "<input type='checkbox' checked='checked' disabled='disabled' name='checkTema[]' value=".$cat->cat_ID."> ".$cat->name."<br>";
Try return false in onclick event
<input
onclick="return false"
checked='checked'
type='checkbox'
name='checkTema[]'
value='.$cat->cat_ID.'> ".$cat->name."<br>"
If you need to POST disabled checkboxes, I suggest using a hidden input before:
<input type="hidden" name="checkbox_disabled" value="<?php echo $checkbox_value; ?>" /> <== Checked and disabled
Then in your PHP code, you can simply check:
if ($_POST['checkbox']) {
//Checkbox wasn't disabled on submission
} else {
//Fallback to using the disabled value:
$disabledVal = $_POST['checkbox_disabled'];
}
Additionally, you can simply undisable all the elements of the form before submission:
$('form').submit(function() {
$(this).find('input').attr('disabled', false);
});
See this question/answer for more information on how you can alternatively do this.
Try this code :
<input disabled='disabled' checked='checked' type='checkbox' name='checkTema[]' value="<?php echo $cat->cat_ID;?>"><?php echo $cat->name;?>
Thanks to a comment, I've got the solution in another SO question
Then my code changed to:
echo "<input type='hidden' name='checkTema[]' value=".$cat->cat_ID." >";
echo "<input type='checkbox' checked='checked' disabled='disabled'> ".$cat->name."<br>";
I have a form which displays values on click from the table through the php's echo function. The echo'ing logic is as follows:
//reading input
if(isset($_POST['add'])){
$scrid=$_POST['sc'];
$desc=mysqli_real_escape_string($_POST['desc']);
$cb=mysqli_real_escape_string($_POST['created']);
$version=mysqli_real_escape_string($_POST['version']);
if($scrid !=0){
if(empty($desc)){$result="Description cannot be Empty";}
elseif(empty($cb)){$result="Created By cannot be Empty";}
elseif(empty($version)){$result="Version cannot be Empty";}
else{
echo $t."empty";
$sql="INSERT INTO testmaster(ScreenID,Description,createdBy,version) VALUES('$scrid','$desc','$cb','$version');";
if(mysqli_query($link,$sql)){
header('Location: testmaster.php');
}else{
echo "Query failed";
}
}
}
}
//passing table values,,,,, works perfectly fine...
if(mysqli_num_rows($sol)>0){
while($row=mysqli_fetch_assoc($sol)){
echo"<tr>";
echo"<td>".$row['Description']."</td>";
echo"<td>".$row['createdBy']."</td>";
echo"<td>".$row['version']."</td>";
echo "</tr>";
}
}
}
if(isset($_GET['testid'])){
$t=$_GET['testid'];
$query="SELECT * FROM testmaster WHERE tid='$t';";
if($sol=mysqli_query($link,$query)){
$modif=mysqli_fetch_assoc($sol);
$d=$modif['Description'];
$c=$modif['createdBy'];
$v=$modif['version'];
$sc=$modif['ScreenID'];
}
//These are the input fields
echo'<td><textarea name="desc" class="form-rounded" cols=50 rows=2
placeholder="Description">'.$d;
echo'</textarea></td>';
echo'<td><input type="text" name="created" class="form-control"
placeholder="Created By" value='.$c.'>';
echo'</td>';
//cancel
echo "<input type='reset' class='btn button2' name='cancel' id='cancel' value='Cancel' style='height:12px; text-align:center; margin-left:10px;' >" ;
Neither cancel button nor the javascript codes specified in Clear text field value in JQuery work.
I guess it's because I echo it.
Can anyone help me with it?
Thanks in advance.... :)
P.S. All the input fields and the cancel button are inside ...
If you've included JQuery in your code, then you can do this like that:
Add clear-onclick (or some other name) class to all fields you want empty
Add onclick handler to the button
Form code
echo'<td><textarea name="desc" class="form-rounded clear-onclick" cols=50 rows=2
placeholder="Description">'.$d;
echo'</textarea></td>';
echo'<td><input type="text" name="created" class="form-control clear-onclick"
placeholder="Created By" value='.$c.'>';
echo'</td>';
Button code
<input type='reset' class='btn button2' name='cancel' id='cancel' onclick="javascript: $('.clear-onclick').val(null)" value='Cancel' style='height:12px; text-align:center; margin-left:10px;' >
You can include jQuery as follows:
echo '<script src="https://code.jquery.com/jquery-3.3.1.js"></script>';
echo "<td><input name='Send' type='button' value='Submit' onClick=location.href='save.php?myDocRegNo=$A&docCat=$C&dcrNo=$Dcr_No
&metTown=$Town_Code&dcrDate=$Dcr_Date&repCode=$Rep_Code&db=$Dbase' /></td>";
I have above link echoed in my php file and all my $ variables are set with values and the link works perfect.
But when I add two more variables &fullTown=$Town&fullRep=$FlRp to the same link and try to submit nothing happens and link does not work.Can anybody can identify the error ?Is there a variable limit for a HTML link?
echo "<td><input name='SendTest' type='button' value='SubmitTest' onClick=location.href='save.php?myDocRegNo=$A&docCat=$C&dcrNo=$Dcr_No
&metTown=$Town_Code&dcrDate=$Dcr_Date&repCode=$Rep_Code&db=$Dbase&fullTown=$Town&fullRep=$FlRp' /></td>";
please try this code its working fine
please try this code its workin fine
echo '<button onclick="window.location.href=\'save.php?myDocRegNo='.$A.'&docCat='.$C.'&dcrNo='.$Dcr_No.'&metTown='.$Town_Code.'&dcrDate='.$Dcr_Date.'&repCode='.$Rep_Code.'&db='.$Dbase.'&fullTown='.$Town.'&fullRep='.$FlRp.'\'">Continue</button>';
echo 'Continue';
please use this code it is working, i think there was only some blank space issue and i have change location.href change to window.location.href and it is working properly.
here is the code
echo "<td><input name='Send' type='button' value='Submit' onClick=window.location.href='save.php?myDocRegNo=$A&docCat=$C&dcrNo=$Dcr_No&metTown=$Town_Code&dcrDate=$Dcr_Date&repCode=$Rep_Code&db=$Dbase' /></td>";
For the last 4 hours I've been struggling to get something to work. I checked SO and other sources but couldn't find anything related to the subject. Here is the code:
<?php
$email=$_SESSION['email'];
$query1="SELECT * FROM oferte WHERE email='$email'";
$rez2=mysql_query($query1) or die (mysql_error());
if (mysql_num_rows($rez2)>0)
{
while ($oferta = mysql_fetch_assoc($rez2))
{
$id=$oferta['id_oferta'];
echo "<input type='radio' name='selectie' value='$id' id='$id'> <a href='oferta.php?id={$oferta['id_oferta']}'>{$oferta['denumire_locatie']}</a>";
echo "</br>";
}
echo "</br>";
//echo "<input type=\"button\" id=\"cauta\" value=\"Vizualizeaza\" onclick=\"window.location.href='oferta.php?id={$oferta['id_oferta']}'\" />";
//echo " <input type=\"button\" id=\"cauta\"value=\"Modifica\" onclick=\"window.location.href='modifica.php?id={$oferta['id_oferta']}'\" />";
echo " <input type=\"button\" id=\"sterge\" value=\"Sterge\" onclick=\"window.location.href='delete.php?id=$id'\" />";
echo "</form>";
echo "</div>";
}
else
{
}
?>
The while drags all of the user's entries from the database and creates a radio button for each one of them with the value and id (because I don't really know which one is needed) equal to the entry's id from the db. I echoed that out and the id is displayed as it should so no problems there.
The delete script works ok as well so I won't attach it unless you tell me to. All good, no errors, until I try to delete an entry. Whatever I choose from the list of entries, it will always delete the last one. Note that I have two other inputs echoed out, those will be the "view" and "modify" buttons for the entry.
I really hope this is not JavaScript related because I have no clue of JS. I think this will be of major help to others having this problem. Please let me know if I need to edit my question before downrating. Thanks!
After edit:
This is the delete script, which as I said earlier works fine.
<?php
if (isset($_GET['id']))
{
$id = $_GET['id'];
echo $id;
require_once('mysql_connect.php');
$query = "DELETE FROM oferte Where id_oferta = '$id'";
mysql_query($query) or die(mysql_error());
//header('Location: oferte.php');
}
else
{
//header('Location: oferte.php');
}
?>
The session is started as well, like this:
<?php
session_start();
?>
The reason the last $id is deleted is because this line is outside/after the while loop:
echo " <input type=\"button\" id=\"sterge\" value=\"Sterge\" onclick=\"window.location.href='delete.php?id=$id'\" />";
You want to move this line inside the loop so that you have a button that executes delete for each radio button.
Update:
To have links to delete and
echo "<input type='radio' name='selectie' value='$id' id='$id'> ";
echo "<a href='oferta.php?id={$oferta['id_oferta']}'>{$oferta['denumire_locatie']}</a> ";
echo "<a href='delete.php?id=$id'>delete</a>";
Also I do not think the radio button is needed here at all since you are not really doing anything with it. You could simply echo out the value of your choice and have these links as follows:
echo $oferta['denumire_locatie'] . ' '; // replace $oferta['denumire_locatie'] with something of your choice
echo "<a href='oferta.php?id={$oferta['id_oferta']}'>{$oferta['denumire_locatie']}</a> ";
echo "<a href='delete.php?id=$id'>delete</a>";
echo "<br />";
The problem, in this case, is JavaScript related, yes. What I recommend you to do is to simply add a Remove link for each item.
echo "<a href='oferta.php?id={$oferta['id_oferta']}'>{$oferta['denumire_locatie']}</a>";
echo " - <a href='delete.php?id={$oferta['id_oferta']}'>Remove</a>";
echo "</br>";
Your $id is outside your while() loop.
The last one is getting deleted because the $id has the last one's value when the loops is exited.
Include all your code :
echo "</br>";
//echo "<input type=\"button\" id=\"cauta\" value=\"Vizualizeaza\" onclick=\"window.location.href='oferta.php?id={$oferta['id_oferta']}'\" />";
//echo " <input type=\"button\" id=\"cauta\"value=\"Modifica\" onclick=\"window.location.href='modifica.php?id={$oferta['id_oferta']}'\" />";
echo " <input type=\"button\" id=\"sterge\" value=\"Sterge\" onclick=\"window.location.href='delete.php?id=$id'\" />";
Inside your while loop.
When the rendered html reaches the browser, it will be something like this:
<input type='radio' name='selectie' value='1' id='1'> <a href='oferta.php?id=1'>TEXT</a>
<input type='radio' name='selectie' value='2' id='2'> <a href='oferta.php?id=2'>TEXT</a>
<input type='radio' name='selectie' value='3' id='3'> <a href='oferta.php?id=3'>TEXT</a>
<input type='radio' name='selectie' value='4' id='4'> <a href='oferta.php?id=4'>TEXT</a>
<br/>
<input type="button" id="sterge" value="Sterge" onclick="window.location.href='delete.php?id=5'" />
With this markup you won't be able to accomplish what you want without using javascript to update the onclick attribute whenever you select a radio button.
On the other hand, instead of using the client-side onclick event you can use the button's default behaviour, which is to submit the form.
You'll just have to set the action attribute:
<form method="post" action="http://myurl.php">
and write the myurl.php page which will just read the posted variable $_POST['selectie'] and call the delete method with the posted id.
<?php
require "../db/dbconfig.php";
$gal=mysql_query("select * from gallery");
$numrows=mysql_num_rows($gal);
if($numrows>=1)
{
echo "<form action='delete.php' method='post' name='f2' id='f2'>";
echo '<table id="rqst" style="display:block;" border="0" cellpadding="12" cellspacing="3" width="500px">';
echo "<tr><th>Tick to select</th><th>Images in Gallery</th></tr>";
while($row=mysql_fetch_array($gal)
{
$imgfile=$row['ImgName'];
$Image="<img src=gallery/".$imgfile." width='230px' height='150px'/>";
$img_name=$imgfile;
echo "<tr>";
echo "<td><input type='checkbox' name='imgs[]' value='$img_name'></td><td>".$Image."</td>";
echo "</tr>";
}
echo "<tr>";
echo "<td colspan='3' align='right'>";
echo "<input type='submit' value='Delete' name='del'></td>";
echo "</tr>";
echo "</table>";
echo "</form>";
?>
This is my code....This will display images from gallery and checkboxes associated with them. When I click delete button with unchecked checkboxes an alert should come like this "Please check at least one checkbox"..How to do that??
My next problem is,,when I click delete button after checked checkbox, alert should come like this=" Do you want to delete?? "...If clicked Ok,the image must be deleted else do nothing...Please help ...Thanks in advance....
check this below link for validation using jquery:
http://jsfiddle.net/susheel61/U3Unk/2/
<form id="form">
First name: <input type="checkbox" name="firstname" class="check"><br>
<button>test</button>
</form>
$("button").on("click",function(e){
var status = $(".check").is(":checked");
e.preventDefault();
if(!status){
alert("this is not checked");
}
});
Yes, you can do it by javascript or jquery to validate whether your atleast one checkbox is select or not. So, for that you need to give a common class for all checkbox as example
<input type="checkbox" name="firstname" class="addchk">
Now in your submit button call a javascript function which validate the matter.
<input type='button' value='Delete' name='del' onclick='delete_checked()' />
Now write a function to validate whether any checkbox is selected.
function delete_checked()
{
var status = $(".addchk").is(":checked");
e.preventDefault();
if(!status){
alert("this is not checked");
}
else
{
// SUbmit yout form
}
}