How to Isset a hyper link? - javascript

Is it possible to isset() a hyperlink?
I can't seems to make it work. I don't know what to do; I looked for many solutions, but they used $_GET or $_REQUEST. I don't want to use those.
I want to make it work like a submit button I am new to PHP and here is what I have done:
<?php
session_start();
if (!isset($_SESSION['suser'])) {
header("location:register.php");
session_write_close();
exit;
}
error_reporting(E_ALL);
include 'conectthis.php';
$suser = $_SESSION['suser'];
mysql_select_db("$suser", $con);
if (isset($_POST['select'])) {
$result = "SHOW TABLES FROM $suser";
$show = mysql_query($result) or die(mysql_error());
if (!$show) {
echo "<script type='text/javascript'>alert('Create Master List First'); </script>";
exit;
}
}
?>
<body>
<hr />
<div align="center"><h1>Selection</h1></div>
<hr />
<form action="select.php" method="post">
<table width="50%" align="center">
<tr><td>Student Record </td><td><a name="select" href="fq1.php">First Period</a></td><td><a name="select2" href="fq2.php">Second Period</a></td><td><a name="select3" href="fq3.php">Third Period</a></td><td><a name="select4" href="fq4.php">Fourth Period</a></td><td><a name="summary" href="summary.php">Summary</a></td></tr></table>
</form></body>
I want a hyperlink to alert message something when the user have clicked a hyper link.
I hope you understand my English.
Thank you.

This is a shot in the dark, but is this what you want?
Show a message which is set through PHP.
Click Me
<script type="text/javascript">
function showMessage(message){
alert(message);
}
</script>
Show a message using just JavaScript.
Click Me
<script type="text/javascript">
function showMessage(){
alert('hello);
}
</script>

This would be done with JavaScript via a click event. PHP would have no part in it.

Related

How to avoid inserting two time in double click time in codeigniter

I am search the other result of related question and that i implement in my code but that not working ,i have 2 button in a form
my form
<form id="InVoice" action="<?php echo base_url('Staff/add_invoice_spare');?>" method="post" class="form-horizontal">
/*-- content herer--*/
<button style="float:right;" type="submit" name="ready" value="Ready For Bill" class="btn btn-danger" style="border-radius:60px;">Add to Ready for Bill</button>
<button style="float:right;margin-left:15px;" type="submit" name="print" class="btn btn-danger" style="border-radius:60px;">Print</button>
<?php echo form_close(); ?>
and used script is
<script type="text/javascript">
$(document).ready(function() {
$("form#InVoice").submit(function() {
alert();
$('button[type=submit]').prop('disabled',true);
return true;
});
});
</script>
this my controller for inserting
public function add_invoice_spare()
{
$bill=$this->input->post('ready');
if($bill)
{
$reg=$this->input->post('rno');
$data=array(
/*-----------datas here-----*/
);
$ans=$this->Bill_model->check_registration($reg);
$form_data= $this->input->post();
$result=$this->Bill_model->invoice_dtls_ready($form_data,$data);
if($result){
redirect('Staff/list_invoice/'.$result);
}
}else{
$reg=$this->input->post('rno');
$data=array(
/*-----------datas here-----*/
);
}
$form_data= $this->input->post();
$result=$this->Bill_model->invoice_dtls($form_data,$data);
if($result)
{
?>
<script type="text/javascript" language="Javascript">
window.open('invoice_pdf/<?PHP echo $result ?>', '_blank');
window.location.href = "invoice_labour";
</script>
<?php }
}
}
but in double click or single click the Add to Ready for Bill button the print button is work why that redirect?
any way to solve this issue and only one time submitte the data ?
thanks in advance!!!
Both the buttons that you are clicking on are of the type submit or they are submit buttons. So the only way to differentiate this will be at the backend.
For eg, according to the above example when you submit the $_POST array will have the submit button value. It is based on this value that you have to build your code logics.
If you click on Print then $_POST['submit'] will be the value will be print and when you click on "Add to Ready for Bill" the $_POST['submit'] value will be ready.
If you want to control it in the Frontend i.e., jQuery end you can by using the preventDefault (the example of which is given by #pradeep) but I suggest you modify the Backend as well to differentiate between these 2 submit buttons.
Hope this helps.

HTML display=none doesn't work

My code:
<?php
if($counter==0) {
echo "value of counter = $counter"
?>
<script type='text/javascript'>
document.getElementById("tt").style.display = "none";
</script>
<?php
}
?>
<html>
<body>
<form action="new_upload.php" method="post" name="myform" enctype="multipart/form-data" id="formform">
<input type='submit' value='Go Back!' name="sbmt" id="tt"
<?php if($counter==0) { ?> display="none" <?php } ?> />
</form>
<p> Submit a different file by clicking the back button in case your file was unable to upload.</p>
</body>
</html>
You can see I have tried to set the property display=none of the submit button through
1) if php condition is true, I added javascript.
2) I added php in my form submit button code.
but it is not working both ways. I can see through the print statement that the value of counter is 0 but then also it is visible.
You are executing the script before the element is created. Move the code below the element to work
There is no such attribute as display, you need to use style="display: none" instead.

jquery + ajax + php (loading jquery library)

So im learning about jquery and ajax. Originally i did an old school php page, where when i submit the form, the data gets stored in a database, and then the webpage loads a new page and tells me i've successfully added a student... I'm not trying to implement ajax and jquery to my code, but i my js script isn't working. I'm trying to call an Alert() just to test if jquery is working, but no alert popup appears when i click the submit button.
This is what i have so far:
addStudent2.php code:
<!DOCTYPE html>
<html>
<head>
<title>Adding Student With AJAX</title>
</head>
<body>
<form action = "userInfo.php" id="myForm" method="post">
<p>Name:
<input type="text" name="name" value=""/>
</p>
<p>Age:
<input type="text" name="age" value=""/>
</p>
<input type="submit" id="submit" value="Add"/>
<div id="result"></div>
<script src="http://code.jquery.com/jquery-3.2.0.min.js" type = "text/javascript"></script>
<script src="my_script.js" type = "text/javascript"></script>
</form>
</body>
</html>
userInfo.php code:
<?php
include('connection.php');
$name = $_POST['name'];
$age = $_POST['age'];
$query = "INSERT INTO student2 (first_name, age) VALUES(?, ?)";
$var = array($name,$age);
$response = sqlsrv_query($conn, $query, $var);
if($response == true){
echo "Student has been added";
}
else{
echo nl2br("Insertion failed\n");
die( print_r( sqlsrv_errors(), true));
}
?>
my_script.js code:
$('input#submit').on('click', function(){
alart(1);
});
i know my javascript or jquery library isn't working, because i'm not getting an alert popup when i click on the submit button.
Could someone please help?
The problem was the js script was not updating on the browser, i had to force refresh the page by pressing "Ctrl + F5" here.
Also I changed input#submit to #submit:
$('#submit').on('click', function(){
alert(1);
});
...and of course changed "alart(1)" to "alert(1)" lol.

how to display value from dropdown form to another php script [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
this is a index.php page where i have dropdown list
when i select the value from dropdown list i wont display that value in user.php page i use javascript onchange
<html>
<head>
<title>Test Selected Dropdown Value</title>
<script type="text/javascript">
function selected_region(){
var vr = document.getElementById("region").value;
alert("Selected region is: "+vr);
}
</script>
</head>
<body>
<form name="selected_region_form" method="POST" action="user.php">
<?php ?>
<select name="region" id="region" onchange="selected_region();">
<label for="region">Odaberite zupaniju:</label>
<option>
<?php
$region_data = all_regions();
while($region = mysqli_fetch_array($region_data)){
$id_region = $region['zupanija_id'];
$name_region = $region['naziv'];
?>
<option value="<?php $id_region; ?>"><?php echo $name_region; ?></option>
<?php
}
?>
</option>
</select>
<input type="submit" name="send" value="Send"/>
</form>
</body>
</table>
</body>
</html>
this is the user.php script
under in td tag-s i wont display selected value from index.php
<?php
include('connect.php');
include('functions.php');
?>
<html>
<head>
<title>User</title>
</head>
<body>
<h1>User</h1>
<h2>selected region:</h2>
<table border="1">
<tr>
<td> <!-- here i need display a selected region --> <td>
</tr>
</table>
</body>
Back
</html>
functions.php script where a fatch my query:
<?php
function confirm_query($result_set){
if(!$result_set){
die("Query data faild!");
}
}
function all_regions(){
global $db_connection;
$query = "SELECT `zupanija_id`,`naziv` ";
$query .= "FROM `zupanija` ";
$query .= "ORDER BY `zupanija_id` ASC";
$zupanije_data = mysqli_query($db_connection, $query);
confirm_query($zupanije_data);
return $zupanije_data;
}
?>
connection script:
<?php
$connect_error = 'Connection faild!';
$select_db_error = 'Database not found!';
$db_connection = mysqli_connect('localhost', 'iwa_2013', 'foi2013') or die($connect_error);
$db_select = mysqli_select_db($db_connection, 'iwa_2013_sk_projekt') or die($select_db_error);
//setup charset to utf-8
mysqli_set_charset($db_connection, 'utf8');
?>
I think the best way to do this is to attach an onchange event handler to your select element, then have it fire off an AJAX request to your PHP script every time the user selects something.
sending a value from drop down box to another page
Your form is actually submitted to the kreiran_zahtjev.php page via the post method so the element you clicked on will be available via the $_POST variable on kreiran_zahtjev.php
Essentially, if you want to access the clicked element, all you have to do is:
$_POST['zupanija']
Also, you shouldn't use the mysql_ extension of PHP, it's insecure and deprecated. You should use either PDO or mysqli.

Passing url parameters in form action attribute

<?php for($i = 0; $i < $pin_num_rows; $i++){ ?>
<form action="/group/<?php echo $group_id ?>?Comment=<?php echo $pin_id[$i] ?>" method="post" id="group-comment-form">
<textarea name="group-comment" id="group-comment" placeholder="Add a comment..." spellcheck="false"></textarea>
</form>
<?php } ?>
This is the some part of my code. As you can see, I am passing the value of pin_id in my form action. The problem is, whenever I post comment, the form submits the value with /group/?Comment=1 but it supposed to submit with 1, when I comment to the first post. So, when I comment to the second post, it supposed pass 2 but it doesn't. It always passes /group/?Comment=1
I did echo this right after my textarea and I see that for every comment form, the number increments as it should be but when I submit, it submits with value 1. I am going crazy.
<?php echo "/group/<?php echo $group_id ?>?Comment=$pin_id[$i]" ?>
I have also this part in my code in the same loop above and it has the same logic but it works. I don't understand why the form part doesn't work.
Edit
Delete
EDIT
I wrote this simple program which demonstrates the same logic that I used for the site and this simple program works but website. I guess the problem is not about the names of form or textarea.
<?php
$inputValue = NULL;
$id = [1,2,3];
if(isset($_POST['inputName'])){
$inputValue = $_POST['inputName'];
echo "<br>Input Value: " . $inputValue;
}
if(isset($_GET['id'])){
$getValue = $_GET['id'];
echo "<br>Get Value: " . $getValue;
}
?>
<html>
<head><title>Multiple Forms in One Page</title></head>
<body>
<br>
Main Page
<br>
<?php for($i = 0; $i < 3; $i++){ ?>
<form action="index.php?id=<?php echo $id[$i] ?>" method="post" name="formName">
<textarea name="inputName"></textarea>
<input type="submit" name="submitName">
</form>
<?php } ?>
</body>
</html>
FOUND THE PROBLEM (BUT STILL NEED FIX)
<script>
$(function() {
$('textarea#group-comment').on('keydown', function(e) {
if(e.keyCode == 13 && !e.shiftKey){
document.getElementById('group-comment-form').submit();
}
});
});
</script>
I use this script to submit my forms. I don't have a submit button to submit. If I use submit button, everything works perfect but if I use this script above to submit the form, it won't work. What should I do to make the script above work?
SOLUTION
After I found where the problem is caused, I created another question to find a fix for the problem.
The answer is here: Solutution

Categories