handling multiple submits in php - php

This is my code.
<?php
$qry5=mysql_query("SELECT * FROM `questions` WHERE `questnTime`=curdate()");
$quest=mysql_fetch_array($qry5);
?>
<form id="form" name="form" action="">
<textarea name="questn" id="questn" readonly="readonly" cols="45" rows="5">
<?php echo $quest['questnId']; ?>.&nbsp
<?php echo $quest['question'];?>
</textarea>
<input type="submit" class="myButton" name="option"
onclick="handleSubmit(this)" value="<?php echo $quest['optiona'];?>"/>
<input type="submit" class="myButton" name="option"
onclick="handleSubmit(this)" value="<?php echo $quest['optionb'];?>"/>
<input type="submit" class="myButton" name="option"
onclick="handleSubmit(this)" value="<?php echo $quest['optionc'];?>"/>
<input type="submit" class="myButton" name="option"
onclick="handleSubmit(this)" value="<?php echo $quest['optiond'];?>"/>
</form>
<?php
if($quest['answer']==$_GET['option']){
$option=$_GET['option'];
}
Javascript code:
<script type="text/javascript">
function handleSubmit(current){
var list = document.getElementsByName('option');
for(var i=0;i<list.length;i++){
if(list[i]!=current)
list[i].disabled=true;
}
alert('all disabled');
}
</script>
CSS:
<style>
input.myButton{
background-image: url('option.png');
background-color:#FFF;
height:32;
width:32;
border-style:hidden;
color: #FFFFFF;
}
</style>
What I require is when user clicks on an option all other options must be disabled. When an option is clicked, I want to get the value. Also I dont want the page to be refreshed. How to do this? The following code dosenot disable the options. Please help me!!!

In this case not make multiple submits put them as a button and when clicked then make all disable except clicked one and change input type as submit.

Related

How to enable a disabled text input field from one page to another

I'm am developing a project in php but my java is not good. I am trying to link two pages. The first page has a buttons including "Other" for donations which should work in a way that a user should click the button be redirected to the next page where the input text field for the amount should not be disabled.
I hope you are able to assist me because i read almost every post here about onclick events and other options and tried them but to no luck.
//Code for the other button
<td style="padding: 6px;">
<span>
<form action="getcreditcard.php" method="POST">
<input type="hidden" value="<?php echo base64_encode(6); ?>" name="id">
<button type="submit" id="donate" value="Other" class="btn btn-warning" style="width: 100%;">Other</button>
</form>
</span>
</td>
//Code for the receiveing page getcreditcard.php
<
} else if (base64_decode($_POST['id']) == 6) {
$p_price ='Add Amount Here.';
$p_currency = 'USD';
$p_name = 'Donation Option 5';
}
>
and
<div class="form-row">
<label>
<span>Amount (USD)</span>
<input type="text" name="amount"placeholder="enter amount " value="$ <?php echo $p_price; ?>" disabled="true" required="true">
</label>
</div>
Use the javascript jquery prop() like this:
<!-- simple example: -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<form>
Input:
<input type="text" name="amount" id="amount" placeholder="enter amount " value="$ <?php echo $p_price; ?>" required>
</form>
<script type="text/javascript">
$(document).ready(function(){
$("#amount").prop("disabled", true);
});
</script>
Can you use readonly
i hope this help you.
<input type="text" readonly value="<?php echo base64_encode(6); ?>" name="id">

Hiding div when is submitted and send values to PHP

<?php
echo $_POST['textvalue'];
echo $_post['radiovalue'];
?>
<div id="hidethis">
<form method="POST" action="">
<label>Tekst Value</label>
<input type="text" name="textvalue">
<label>Radio Value</label>
<input type="radio" name="radiovalue" value="autogivevalue">
<input type="submit" id="submit" name="submit" value="submit">
</div>
http://jsfiddle.net/Bjk89/2/ here is it with the jQuery.
What i try to do is to hide the <div id="hidethis"> when it's clicking submit.
I know i can make another page where i can recieve the values without the <form> section, but i want to put both in one page, make the <div id="hidethis"> hidden after submit.
So i'll be able to get echo $_POST['textvalue']; and echo $_post['radiovalue']; as results
RESULT MUST BE LIKE
A Text // This is the value you input into Tekst Value
autogivevalue // This is the value from the radio button
----- INVISIBLE -----
<form is hidden because we set it in jQuery so>
</form>
Try this. No need to use jQuery here.
<?php
if($_POST) {
echo $_POST['textvalue'];
echo $_post['radiovalue'];
} else {
?>
<form method="POST" action="">
<label>Tekst Value</label>
<input type="text" name="textvalue">
<label>Radio Value</label>
<input type="radio" name="radiovalue" value="autogivevalue">
<input type="submit" id="submit" name="submit" value="submit">
</form>
<?php
}
?>
Try adding '#' in your jquery code. Your version does not have # next to submit. Also your form is missing a closing tag here and in your JSFiddle code.
Try this:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function () {
$('#submit').click(function () {
$('form').submit();
$('#hidethis').hide();
});
});
</script>
<form method='post' id="hidethis" name='form'>
<input type="text" name="textvalue">
<input type="radio" name="radiovalue" value="1">
<input type="button" id="submit" name="submit" value="submit">
</form>

want to write code for popup window from my given code

i have a simple website which is written by php code. i have a detect button on my page and given below code is writen for this function but my problem is i need a popup window when the detect link is clicked. i have tired to set a code in my created code but i am not able .kindly please help me solve this problem.
<?php
/*echo "permessi".$permessi;
echo "<br>id".$id_nome;*/
if($action=='canc'){?>
<h1>are you sure want to delect the course?</h1>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="canc1" style="float: left; margin-left:25px;">
<input type="hidden" name="idcorsocanc" value="<?=$canc_id?>">
<input type="hidden" name="action" value="">
<input type="submit" name="ok" value="Si,cancella" class="puls_invia">
</form>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="canc2" style="float: left; margin-left:25px;">
<input type="hidden" name="action" value="">
<input type="submit" name="ok" value="NO" class="puls_invia">
</form>
<?php
}
Try this
<script>
function open_win()
{
window.open("URL HERE")
}
</script>
<input type="button" value="Open Window" onclick="open_win()">

Getting button value on click and echo it

i am a beginner in php and my first task is to build a calculator and I am here to ask how to get a value from a button and just echo it on the same page. I am trying through method post using isset but enable to display any value on the same page.
<form action="" method="POST">
<input type="button" value="0" name="zero">
</form>
<?php
if (isset($_POST["zero"]))
{
echo $_POST["zero"];
}
?>
Only an input[type=submit] will submit the form onclick. It is valid to have multiple submit buttons:
<form action="" method="POST">
<input type="submit" value="0" name="mybutton">
<input type="submit" value="1" name="mybutton">
<input type="submit" value="2" name="mybutton">
</form>
<?php
if (isset($_POST["mybutton"]))
{
echo $_POST["mybutton"];
}
?>
If you want to use input[type=button] then you will need some Javascript to trigger the submit, and a hidden input to transport the value.
<script>
window.onload = function(){
document.getElementsByName("mybutton").onclick = function(){
document.getElementsByName("postvar")[0].value = this.value;
document.forms.myform.submit();
}
};
</script>
<form name="myform" action="" method="POST">
<input type="hidden" name="postvar" value="" />
<input type="button" value="0" name="mybutton">
<input type="button" value="1" name="mybutton">
<input type="button" value="2" name="mybutton">
</form>
<?php
if (isset($_POST["postvar"]))
{
echo $_POST["postvar"];
}
?>
Change
<input type="button" value="0" name="zero">
To
<input type="submit" value="0" name="zero" />
Add an event handler if you want to do it via button click.
Try this
<form action="" method="POST">
<input type="submit" value="0" name="zero">
</form>
<?php
if (isset($_POST["zero"]))
{
echo $_POST["zero"];
}
?>
Use
<input type="submit" value="0" name="zero">
else if you want to use button use javascript
<form action="" method="POST">
<input type="button" value="0" name="zero">
</form>
<script type="text/javascript">
$("input[type='button']").click(function(){
alert(this.value);
});
</script>

why does my jquery dialog box disappears after a few seconds?

i have a form with a textarea and a button. if the button is clicked while the textarea is empty, the form will reload and generate an error message. otherwise, the form will redirect to another page. now, i integrated a jquery dialog box. when the button is clicked the dialog box should appear and ask a yes or no question. the problem is when i click the button the dialog box appears but disappears after a few seconds. how can i fix this? i'm using php for the form and jquery for the dialog box.
ps. in php, when you click a button in a form the page will reload right? i think this has something to do with the disappearing of the box because it disappears right before it reloads.
here's my code
<form id="form1" name="form1" method="post" action="<? echo $PHP_SELF; ?>" enctype="multipart/form-data" onsubmit="myRedirect();">
<p class="style16">
<div align="left">
<p><span class="style5">Rules:</span>
<?
if($_POST['continue']) {
if($_POST['rules']==null) {
echo $_SESSION['nature']."<font color='red' size='3'><b>Please enter the rules.</b></font><br>";
}
}
?>
<input type="hidden" name="other_id" value="<? echo $_SESSION['other_id']; ?>">
<input type="hidden" name="hidden1" value="<? echo $_SESSION['hidden1']; ?>">
</p>
<p>
<textarea name="rules" rows="7" cols="49"></textarea>
<br />
</p>
<div id="dialog" title="Empty the recycle bin?">
<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>Is the judge/speaker/facilitator from UST?</p>
</div>
<p><input type="submit" name="continue" id="continue" value="Continue"/>
<input type="reset" name="clear" value="Clear"></p>
<center>
<!--<input type="submit" name="clear2" id="clear2" value="Clear" onClick="textfield.value="" textfield2.value="" textarea.value="" textarea2.value=""
textarea3.value="" textarea4.value="" textarea5.value="" textarea6.value="" file.value="" "/>-->
</center>
</p>
</div>
</form>
To keep the form from submitting, you need a "return false" in its onsubmit event.

Categories