onclick change the name in drop down box - php

what i am trying to do is when i click on the submit button and try to get the value it is not displaying it properly . I am writing the code of 2 file down 1) enable.php 2) abc.php
File Name : enable.php
<html>
<head>
<script type="text/javascript">
function showdetail(boxid){
document.getElementById(boxid).style.display = "block";
}
function hidedetail(boxid){
document.getElementById(boxid).style.display = "none";
}
</script>
</head>
<body>
<form name="abc" method="post" action="abc.php">
<ul>
<li><a id="r" href="#" title="" alt="" onclick="showdetail('res'); hidedetail('comm');">bb</a></li>
<li style="width: 1px;">|</li>
<li style="width:85px;"><a id="r" href="#" title="" alt="" onclick="showdetail('comm'); hidedetail('res');">Cc</a></li>
<li style="width: 2px;">|</li>
</ul>`
<div id="res" style="display:none;">
<select id="pr" name="pr" class="textarial12 textcolorgrey flot_left">
<option value="Hello">Hello</option>
</select>
</div>
<div id="comm" style="display:none;">
<select id="pr" name="pr" class="textarial12 textcolorgrey flot_left">
<option value="Hi">Hi</option>
</select>
</div>
<input type="submit" value="submit" />
</form>
</body>
</html>
File Name : abc.php
<?php
$PropertyType=$_POST[pr];
echo $PropertyType;
?>

$_POST elements must be referenced as a string. Instead of:
$PropertyType=$_POST[pr];
please use:
$PropertyType=$_POST['pr'];

Related

Multiple select Form Value String

I need a multiple select form, like this:
<!doctype html>
<html lang="en">
<head>
</head>
<body>
<form action="" method="get">
<p>
<select class="multiple normal-selectbox" id="RW" name="RW" multiple="multiple">
<option value="N" ><span class="input-group"><strong>Region Nord</strong></span></option>
<option value="HAM" ><span class="input-group">Hamburg</span></option>
<option value="HAJ" ><span class="input-group">Hannover</span></option>
<option value="BRE" ><span class="input-group">Bremen</span></option>
</select>
<div class="form-group submit f0 " data-fid="f0" style="position: relative;">
<div class="progress" style="display: none; z-index: -1; position: absolute;">
<div class="progress-bar progress-bar-striped active" role="progressbar" style="width:100%">
</div>
</div>
<button type="submit" class="btn btn-primary btn-lg" style="z-index: 1;">
GO
</button>
</form>
</body>
</html>
After submit it hast to get Values as String in URL it get it so:
...?RW=N&RW=HAM&RW=HAJ&RW=BRE
But I need it so:
Rw=HAMxHAJxBRE ...
i find this
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
var x = $("form").serializeArray();
$.each(x, function(i, field){
$("#results").append(field.name + "x" + field.value + " ");
});
});
});
</script>
</head>
<body>
<form action="" method="get">
First name: <input type="text" name="FirstName" value="Mickey"><br>
Last name: <input type="text" name="LastName" value="Mouse"><br>
</form>
<button>Serialize form values</button>
<div id="results"></div>
</body>
</html>
But it doesn't Get Values to URL
Do you have any idea to solve my problem?
Regards
Hello friends thank you for your help, I made some code the result is what I want to string in to URL i don't know why
hier is the Code
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
var x = $("form").serializeArray();
$.each(x, function(i, field){
$("#results").append("" + field.value+"x");
});
});
});
</script>
</head>
<body>
<form action="" method="get">
<label>
<select name="RW" multiple class="multiple normal-selectbox" id="RW">
<!--<option value="-" selected="selected" >alle Abflughäfen</option>-->
<optgroup label="Norden">
<option value="N" ><span class="input-group">Region Nord</span></option>
<option value="HAM" ><span class="input-group">Hamburg</span></option>
<option value="HAJ" selected ><span class="input-group">Hannover</span></option>
<option value="BRE" ><span class="input-group">Bremen</span></option>
</select>
</label>
</form>
<button>Serialize form values</button>
<div id="results"></div>
</body>
</html>
also the string should be RW="results"
Assuming that you are using PHP on the server-side - as implied by the PHP tag on this post, PHP should show this as an Array automatically. For an ordinary field, $_REQUEST['RW'] would be a single value (e.g., "HAM") for a multiple select it will be an array (e.g., ["HAM","HAJ"]). Just let PHP do the work for you and don't try to decode the URL yourself.

Form action not refreshing properly

I have a problem whit form submission. I have a html form and the action simpli doesnt want to work. maybe i am doing something wrong, but here take a look at it:
<form action="add.php" method="post" autocomplete="off">
<input type="text" name="title" placeholder="Title" style="width:300px;">
<select id="type" name="type">
<option value="0">Matrix</option>
<option value="1">LoL</option>
<option value="2">Dota 2</option>
</select><br />
<textarea rows="30" cols="90" placeholder="Content here" name="content"></textarea><br />
<input type="submit" value="DODAJ">
</form>
so when i click on the button i does refresh the page but nothing is displayed. I't worked in local but when i upload it online nothnig, just a blank page. And the stuff that has to go to the database doesnt go. no errors, no nothing.
help?
Here's the complete code for that add.php page:
<?php
include '../php/db/init.php';
include '../php/db/connection.php';
protect_page();
admin_protect();
if(isset($_SESSION['logged_in'])){
if(isset($_POST['title'], $_POST['content'], $_POST['type'])){
$title = $_POST['title'];
$content = nl2br($_POST['content']);
$content_short = substr($content,0, 150);
$type = $_POST['type'];
echo $type;
die();
if(empty($title) or empty($content) or empty($type)){
$error = 'Potrebno je popuniti sva polja!';
} else {
$query = $pdo->prepare('INSERT INTO articles (article_title, article_content, article_content_short, article_timestamp, article_type) VALUES (?,?,?,?,?)');
$query->bindValue(1,$title);
$query->bindValue(2,$content);
$query->bindValue(3,$content_short);
$query->bindValue(4,time());
$query->bindValue(5,$type);
$query->execute();
redirect('http://www.matrixgamingns.com/admin/index.php');
}
}
?>
<html>
<head>
<title>Matrix Gaming Admin Panel</title>
<link rel="stylesheet" type="text/css" href="../css/admin.css">
<link rel="stylesheet" type="text/css" href="../css/reset.css">
</head>
<body>
<div id="home">
<div id="wrapper">
<?php include 'adminmenusidebar.php'; ?>
<div id="field">
<h3 style="font-size:22px;">Dodaj vest</h3>
<?php if(isset($error)){ ?>
<small style="color:#aa0000"> <?php echo $error?> </small>
<br/>
<?php }?>
<br />
<form action="add.php" method="post" autocomplete="off">
<input type="text" name="title" placeholder="Title" style="width:300px;">
<select id="type" name="type">
<option value="0">Matrix</option>
<option value="1">LoL</option>
<option value="2">Dota 2</option>
</select><br />
<textarea rows="30" cols="90" placeholder="Content here" name="content"></textarea><br />
<input type="submit" value="DODAJ">
<?php
ini_set('display_errors','On');?>
</form>
</div>
</div>
</div>
</body>
</html>
<?php
} else {
redirect('http://www.matrixgamingns.com/admin/index.php');
}
?>
Get rid of the die() after echo $type;
By including a die() function, it stops all in its tracks, just like return does and nothing gets executed afterwards.
You could use the login form example posted here: HTML Dynamic Forms Generator
I downloaded the source code for the login form and it saved me lots of time.

HTML form not submitting values

This is my form and it is not passing any values.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<style type="text/css">
.welcome {
color: #FFFFFF;
text-align: center;
background-color:red;
font-weight:bold;
height: 50px;
}
</style>
<script type="text/javascript">
function submitimg(myvalue)
{
document.getElementById('type').value = myvalue;
document.getElementById('survey').submit();
}
</script>
</head>
<body>
<table style="height: 232px; width: 500px">
<form action="" method="post" name="survey" id="survey">
<tr>
<td>
<div class="welcome"><br>Welcome!</div>
</td>
</tr>
<tr>
<td>
<ul>
<br>
<br>
<div id="question1" style="display: inline;">
<h3>
Are You 30+ Years Old?
</h3>
<div style="height: 10px"> </div>
<input type="button" name="age30" value="Yes" onclick="document.getElementById('question1').style.display='none';document.getElementById('question2').style.display='inline';">
<input type="button" name="age30" value="No" onclick="document.getElementById('question1').style.display='none';document.getElementById('question2').style.display='inline';">
</div>
<div id="question2" style="display: none;">
<h3>
Are You Looking for a Date?
</h3>
<div style="height: 10px"> </div>
<input type="button" name="date" value="Yes" onclick="document.getElementById('question2').style.display='none';document.getElementById('question3').style.display='inline';">
<input type="button" name="date" value="No" onclick="document.getElementById('question2').style.display='none';document.getElementById('question3').style.display='inline';">
</div>
<div id="question3" style="display: none;">
<h3>
Which Girl Is Your Type?
</h3>
<div style="height: 10px"> </div>
<input type="hidden" name="type" value="">
<img src="http://healthystartups.com/storage/600px-MA_Route_1.png?__SQUARESPACE_CACHEVERSION=1319542839834" width="100px" style="cursor:pointer;" onclick="submitimg('type1');">
<img src="http://jenntgrace.com/wp-content/uploads/2012/12/2.png" width="100px" style="cursor:pointer;" onclick="submitimg('type2');">
<img src="http://3.bp.blogspot.com/-Q_owQUxNjdQ/Te3ALCmT3oI/AAAAAAAAAnk/wv9r0b0MT-g/s1600/600px-MA_Route_3.svg_.jpg" width="100px" style="cursor:pointer;" onclick="submitimg('type3');">
<img src="http://4.bp.blogspot.com/-wY_qFr2pcAs/UCxhAayJ6oI/AAAAAAAAC6w/PgtLs2O_4g8/s1600/4.png" width="100px" style="cursor:pointer;" onclick="submitimg('type4');">
</div>
</ul>
</td>
</tr>
</form>
</table>
<?php
$age30 = $_POST['age30'];
$date = $_POST['date'];
$type = $_POST['type'];
echo $_POST['age30'];
?>
</body>
</html>
There is error in your html. Names should be unique. In your case it's better to use radio than button.
<input type="radio" name="age30" value="yes">
<input type="radio" name="age30" value="No" >
echo $_POST['age30'];
Test this code.
Also change your submiting function to this(Jquery Example)
$(function(){
$(".submit_img").click(function (){
$("#survey").submit(); // this line will submit form
});
});
now when you add to element 'submit_img' class, then if someone click this element the form with id=survey will be submitted.
<img src="http://jenntgrace.com/wp-content/uploads/2012/12/2.png" width="100px" style="cursor:pointer;" class="submit_img">
DEMO
Try rename inputs like this
<input type="button" name="date[]" value="Yes">
<input type="button" name="date[]" value="No">
Please specify an action for your form. Create another php file to get the POST variables and put that name inside action.

JavaScript for validate only filed which is checked

I have some PHP code in which is using codeigniter. How can I check validation on the filed that are marked check? My code is below.
Can you please let me know how can I check if item is checked and force the validation accordingly?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/Javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>/site.css"></link>
</head>
<body>
<script type="text/Javascript">
$(function () {
$('.checkall').click(function () {
$(this).parents('fieldset:eq(0)').
find(':checkbox').attr('checked', this.checked);
});
});
</script>
<? $attributes = array('class' => '', 'id' => ''); ?>
<? echo form_open('ShoppingListController', $attributes); ?>
<div class="divTable">
<fieldset>
<!-- these will be affected by check all -->
<div class="divRow">Product Name | Quantity | Packages</div>
<div class="divRow"><input type="checkbox" size="100" class="checkall"> Check all</div>
<br>
<?php foreach ($records as $rec) {
?>
<div class="divRow"><input type="checkbox">
<input size="5" type="hidden" value="<? echo $rec->id; ?>" name="id"></input>
<input size="20" type="text" value="<? echo $rec->name; ?>" name="name"></input>
<label for="quantity">Value <span class="required">*</span></label>
<span class="required"><?php echo form_error('quantity'); ?></span>
<input size="5" type="text" value="" name="quantity"></input>
<select name="package">
<option name="case">Case</option>
<option name="box">Box</option>
<option name="box">Single Bottle</option>
</select>
</div>
<br>
<?
}
?>
</fieldset>
</div>
<div><input type="submit" name="submit"/></div>
</form>
</body>
you can use code below:
var divRows = $('.divRow');
var count = divRows.length;
divRows.each(function() {
if ($(this).find('input[type=checkbox]').is(':checked')) {
count--;
}
});
if (count != 0) {
alert(count + ' checkboxes not checked');
}
http://jsfiddle.net/SKgA8/

jquery find closest given class

I've created a option list with radio buttons and it looks like this:
<div class="option_list" style="width:150px; display:none; margin-top:0px;">
<form id="formSales">
<ul>
<li><input type="radio" value="2012" name="YEAR" /></li>
<li><input type="radio" value="2011" name="YEAR" /></li>
<li><input type="radio" value="2010" name="YEAR" /></li>
<li><input type="radio" value="2009" name="YEAR" /></li>
</ul>
<input type="hidden" value="1" name="SALES" />
</form>
</div>
<div class="table_content_results">
<div class="results"></div>
</div>
With jquery I post the form and I want to get that result in the div with the class results
underneath the div with class option_list
$(".option_list ul li").click(function() {
$.ajax({
type: "POST",
url: "data.php",
data: $(this).parent('form').serialize(),
complete: function(data) {
$(this).siblings('.results').html(data.responseText);
}
});
$(this).parent(".option_list").slideToggle(200);
var value = $('input[name="YEAR"]:checked').val();
$("#yearValue").text(value);
});​
I use the class in jQuery because i want to duplicate the same option_list for another form on the same page.
The problem is to get the results of data.php in the div with class results.
I hope somebody has an answer for me.
Thanks in advance!
Change
$(this).siblings('.results').html(data.responseText);
to
$(this).parents('div').next().children('.results').html(data.responseText);
$(this) is a li so you need to find the parent div before finding the next child with the class results
Cut down version - but working example -> http://jsfiddle.net/bFHJc/
Updated
Following discussions in chat it seems the markup in the question was incorrect .. here is the full markup :
<div class="table_settings">
<div class="stats_options" style="width:130px;">
<div style="float:left">Boekjaar: <span id="getYearPurchase">2012</span></div>
<div style="float:right; margin-top:11px;"></div>
<div class="clear"></div>
</div>
<div class="option_list" style="width:150px; margin-top:0px;">
<form id="formSales">
<ul>
<li>one</li>
<li>two</li>
</ul>
<input type="hidden" value="1" name="SALES" />
</form>
</div>
</div>
<div class="table_content_results">
<div class="results"></div>
</div> ​
And this is the JavaScript 'locator' used to post to the results div:
$(this).parents('.table_settings').siblings('.table_content_results').children('.results').html();
Here is an example -> http://jsfiddle.net/9YWmW/3/
Try this:
$(this).siblings('.results').html(data);
instead of
$(this).siblings('.results').html(data.responseText);
in jquery you need not write responseText,It is needed in javascript ajax
or you can just write
$('div.results').html(data);

Categories