Display that User Current Location as the value of the Textbox [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have here a codes that displays the current location of the user, this codes is already working. My problem is how to put the id "#location" as the value for my textbox in html form so that the current location will put in a textbox form.
$(document).ready(function(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showLocation);
} else {
$('#location').html('Geolocation is not supported by this browser.');
}
});
function showLocation(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
$.ajax({
type:'POST',
url:'../geo/getLocation.php',
data:'latitude='+latitude+'&longitude='+longitude,
success:function(msg){
if(msg){
$("#location").html(msg);
}else{
$("#location").html('Not Available');
}
}
});
}
HTML:
Location: <input id="location" type="text" value="" size="50">
<br>

If the ajax request works correctly (we don't know what kind of data it returns), when the problem is in wrong choice of method.
Use .val() instead of .html() because you can't insert html inside input.
if (msg) {
$("#location").val(msg);
} else {
$("#location").val('Not Available');
}

Related

Accessing multiple PHP pages through array [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I need some help with this PHP pages.
I don't understand
session_start();
require("config/db.php");
if(isset($_GET['page'])){
$pages=array("menu","cart");
if(in_array($_GET['page'], $pages)) {
$_page=$_GET['page'];
}else{
$_page="menu";
}
}else{
$_page="menu";
}
?>
My code at the bottom calls $_page and it will display that PHP page,
in this case, menu.php. How do I make it call menu2.php if I were to select an option that changes the value to menu2?
EDIT:
Thanks for all your comments! I would like to add on that this is just a container in the website, and my output will be derived from
Please look at the sample code i created below, this should give you an idea, I hope.
<section href="#" id="showItem"></section>
<select id="options">
<option value="page1.php">Page 1</option>
<option value="page2.php">Page 2</option>
</select>
<script type="text/javascript" src="js/jquery-2.2.0.min.js"></script>
<script type="text/javascript">
var options = $('select#options').val();
var section = $('section#showItem');
var getPage = function (url) {
$.get(url).success(function (data) {
section.html(data);
}).error(function () {
section.html("error loading page");
});
};
$('select#options').change(function () {
var options = $('select#options').val();
getPage(options);
});
$(document).ready(function () {
getPage(options);
});
</script>
Use
header("Location:" . $_page . ".php");
where location can be any valid url/page name on the server relative to the current document.
just try: header('Location:'.$_page.'.php'); it will redirect to selected page

How to fetch data from drop-down menu in PHP? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to select multiple elements from a drop down menu bar and show it in the next text box without submitting the form?
Suppose I have elements like "car,dog,rat,bike,tv,fridge,etc,etc " showing in the drop down menu. I want to select car,bike,tv,fridge and fetch the data in the next text area without going to a new page i.e I want to show the user selected items but only from drop down box only.
See if this is what you want
<select id="select" multiple>
<option value="1">car</option>
<option value="2">dog</option>
<option value="3">rat</option>
<option value="4">bike</option>
</select>
<textarea id="txt1"></textarea>
your js:
$(document).ready(function(){
$( "#select" )
.change(function () {
var str = "";
$( "select option:selected" ).each(function() {
str += $( this ).text() + " ";
});
$( "#txt1" ).text( str );
})
.change();
});
WORKING DEMO
Do not forget to include jquery.js file
Welcome To StackOverflow! As stated in the comments, for a better answer try providing what you have already as there are multiple ways to answer this type of question.
Having said that, this should help:
$('.dropdown').on('change', function() {
var value = $(".dropdown").val();
$('textarea').val(value); //insert string into textarea
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select class="dropdown" multiple>
<option>Rock</option>
<option>Paper</option>
<option>Scissors</option>
<option>Lizard</option>
<option>Spock</option>
</select>
<textarea></textarea>
This is using jQuery, so remember to include the jQuery file.

php variable changes when clicked on html link [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to make a game in HTML and PHP and I'm pretty new to coding. The point is I need to execute a PHP script by clicking an HTML element. Is this possible?
My code would look something like this
$money = 100;
and by clicking on:
<a>rob a shop</a>
it must excecute:
function rob_shop(){
$money += 75;
echo "You now have $money $";}
Try this, is PHP:
<?php
if (isset($_GET['money'])) {
$money = rob_shop($_GET['money']);
echo 'You now have: '.$money.'<br>';
} else {
$money = 100;
echo 'You now have: '.$money.'<br>';
}
echo 'rob a shop';
function rob_shop($money){
$money = $money + 75;
return $money;
}
?>
But the best way to do it is with ajax to avoid refreshing the page.
Add extra param to link and check with php and call function.
rob money
Then check for link
if (isset($_GET['fun']))
{
runFun();
}
you will need to use javascript and an ajax call or you could just do it in javascript.
<a id="shop">rob a shop</a>
<div id="response"></div>
// include jquery
<script>
$( "#shop" ).click(function() {
var money = money + 75;
$("#response").html( "YOU NOW HAVE $"+money );
// or make an ajax call to a php script and return the value
});
</script>

html clear placeholder on submit [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am using placeholder attribute provided in html 5 to get placeholder effect.
<input id="search" class="hasPlaceholder" type="text" placeholder="Personal Trainer"
value="" name="search">
also I have added code to clear the placeolder on submit.
$(function() {
if(!$.support.placeholder) {
var active = document.activeElement;
$(':text').focus(function () {
if ($(this).attr('placeholder') != '' && $(this).val() == $(this).attr('placeholder')) {
$(this).val('').removeClass('hasPlaceholder');
}
}).blur(function () {
if ($(this).attr('placeholder') != '' && ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))) {
$(this).val($(this).attr('placeholder'));
$(this).addClass('hasPlaceholder');
}
});
$(':text').blur();
$(active).focus();
$('form').submit(function () {
$(this).find('.hasPlaceholder').each(function() {
var input = $(this);
input.removeClass('hasPlaceholder');
if (input.val() == input.attr('placeholder')) {
input.removeAttr('placeholder');
input.val("");
}
});
});
}
});
but still it gives placeholder value after submit.
When I entered the last part of your question (Please suggest where i can get list of all Occupation/Industry in excel format) into google, I came across this link on page 1. It has a link to this spreadsheet which contains the exact thing you are looking for. I like helping folks, but seriously, do a little research and googling first.
11-0000 Management Occupations
11-1000 Top Executives
11-1010 Chief Executives
11-1011 Chief Executives
11-1020 General and Operations Managers
11-1021 General and Operations Managers
11-1030 Legislators
11-1031 Legislators
Example Data.

I figure it out myself [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
in the updates.. with my code above, it is working if i only choose 1 row but when i have chosen more than 1 row, the value in the last row that i inserted is the only value that mysql is using to updates all rows. 2 yes it is intended. i need it for my updates, 3rd sorry, but i am using CSS though i will clean my code after i finish my program, im just stack here
This is my parent window HTML code
JAVASCRIPT
function MM_openBrWindow(theURL,winName,features) { //v2.0
var chkValue = "";
var counter = "";
for (var i=0; i < document.myForm.chkbox.length; i++)
{
if (document.myForm.chkbox[i].checked)
{
chkValue = chkValue + document.myForm.chkbox[i].value + " ";
}
counter ++;
}
var queryString = "&chkValue=" + chkValue;
// location = "featuredaction.php" + queryString
//var queryString = "id=" + id;
var theURL = theURL + queryString;
//var tbreceiptno= document.getElementById('checkbox').value;
window.open(theURL,winName,features);
}
I think i will fgure it out my own thanks everyone..
You have fault in your second line $chkValueArr=explode(" ", $chkValue);. You dont have to explode it. You already got an Array of checkbox value when you wrote $chkValue=$_GET['chkValue']; Assuming your HTML form is something like:
<input type="checkbox" name="chkValue[]" value="val 1">
<input type="checkbox" name="chkValue[]" value="val 2">
<input type="checkbox" name="chkValue[]" value="val 3">
You can loop over all checkbox values by:
foreach($chkValue as $chk)
{
echo $chk;
}
This will print val 1, val 3 if you selected those checkboxes in your form.
You can check the array by writing print_r($chkValue)

Categories