I've a problem with iframe. My first file filtre.html contain iframe with a basic code like this:
<iframe name="filtre_demo" src="http://localhost:8888/modules/filtredemo/filtre.php" scrolling="no" height="220" width="220" frameborder="no"></iframe>
This file filtre.php is a drop down dynamic list with 3 levels (PHP/MYSQL).
Filtre.php this file is actually a dynamic dropdown 3 levels and will find info in a DB. The submit sent to a URL and all working fine.
My problem is with iframe. When I click on submit, target page is found in this part of 220x220 instead of reloading the parent page.
I tried several solutions to no avail. Here is part of my php file (I deliberately truncated several parts) including the header location and the form:
$ligne=mysql_fetch_assoc($rech_lien);
$lien=$ligne['lien'];
header('Location:'.$lien.'');
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
</head>
<body style="font-size: 75%; width: 210px;">
<form action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post" id="chgcategories">
<fieldset style="border: 0px">
<select name="modele" id="modele" onchange="submit();">
<option value="-1">-Choisissez un modele-</option>
<select name="sous_categorie" id="sous_categorie">
<option value="-1">-Sous-cat-</option>
</select>
<input type="hidden" name="nb_listes" value="3" />
<br /><br />
<input type="submit" name="ok" id="ok2" value="Envoyer"/>
</form>
I also tried with javascript but without success. In this configuration there I removed the line:
header('Location:'.$lien.'');
Here is the javascript code in the header:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
<script type="text/javascript">
parent.document.location.href="<?php echo $lien; ?>";
</script>
</head>
<body style="font-size: 75%; width: 210px;">
The problems in this case is that the document load loop.
Anyway, I'm stuck, I thank you in advance for your help.
Vincent
If I understand what's happening, the buttons are targeting the contents of the iframe and loading the page inside that, instead of the actual window? If that's the case, set the target attribute the either _parent or _top and that should target the actual window.
You can try this javascript code:
<?php
/*-------Your Php Code-----*/
\\Replace this code #header(location)
echo "<script>";
echo "window.location='yourloation.php';";
echo "</script>";
/*-------Your Php Code-----*/
?>
Related
I have a admin page where i update number in text-box it gets updated and inserted in database and from there it gets displayed on page but updated text is not getting updated on WordPress page immediately every time it needs a hard refresh (through hard refresh plugin or I have to activate or deactivate WordPress theme) how to solve this issue. please help. here is my complete code please try to help. first admin page:
<?php
use Gt\Gt\Database\Database;
extract($_POST);
if(isset($save))
{
DataBase::getupdate($ticketsavailable);
header('location: http://localhost:82/?page_id=1000');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>update page</title>
</head>
<body>
<form action="" method="POST">
<label class="update_heading"> UPDATE </label>
<label for="update" class="update"> Update Number: </label><input type="textbox" id="ticketsavailable" name="ticketsavailable" value="<?php
echo $ticketleft[0]->ticket_available ;?>" >
<br><br>
<input type="submit" name="save" value="Submit">
</form>
</body>
</html>
//getupdate() functions
public static function getupdate($ticketsavailable)
{
global $wpdb;
$wpdb->insert(
'tickets_available',
array(
'ticket_available' => $ticketsavailable
),
array(
'%s',
)
);
$last_donation_id = $wpdb->insert_id;
return $last_donation_id;
}
I have Installed wordpress plugin to excecute php code on wordpress page:
now this number is displayed on wordpress page through this code:
global $wpdb;
$eventslist = $wpdb->get_results("select ticket_available from tickets_available order by id desc limit 1");
$tickets_left = $eventslist[0]->ticket_available;
echo $tickets_left;
number is getting updated and displayed on wordpress page but its hard refresh every time,please help.
I am trying to send a PHP variable to my javascript. In order to do this, I encode the php variable with json, send it to my view with my controller, use it as a value in a hidden html form, and then pull the value with js, using parseJSON to get the final product.
HTML (I'm using laravel, the brackets are equivalent to php tags):
<input type="hidden" id="js-helper-artist-likes" name="js-helper-artist-likes" value="{{$artist_likes}}">
JS
var artist_likes = $('#js-helper-artist-likes').val();
console.log(artist_likes);
In the page source, I see that the value is populating with the json string, but when I print it to the console from my js like the above, all that is showing is: [{
I am not sure why this is.
I want to perform:
var artist_likes_decoded = $.parseJSON(artist_likes);
to get the decoded variable in JS, but this is impossible without the encoded string coming up correctly in the artist_likes variable in js.
Any ideas what I'm doing wrong? Thank you.
<input type="hidden" id="js-helper-artist-likes" name="js-helper-artist-likes" value="{{ echo $artist_likes}}">
You could use:
<input type="hidden" id="js-helper-artist-likes" name="js-helper-artist-likes" value="<?= json_encode($artist_likes) ?>">
<?php
$yourVariable ="something";
$arr = json_encode(array("name"=>$yourVariable));
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<input type="hidden" id="js-helper-artist-likes" name="js-helper-artist-likes" value='<?php echo $arr; ?>'>
<script>
$(document).ready(function(){
var artist_likes = $('#js-helper-artist-likes').val();
console.log($.parseJSON(artist_likes));
});
</script>
</body>
</html>
Hello I came across a weird behavior with an onclick attribute regarding form submission.
Page on Server:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head lang="en-us" >
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Return Form Example</title>
<script type="text/javascript">
function doSomething(){
alert("hey");
return false;
}
</script>
</head>
<body>
<form action="submit.php" method="post">
<input type="submit" onclick="return doSomething()" value="click me!">
</form>
</body>
</html>
In this example, running on my server, when I click the submit button I get an alert saying hey and I stay on the current page. However, I tried to set this same example up on jsfiddle and I get an 404 error meaning the form was submitted. I cannot figure out why this occurs.
Here is the jsfiddle where I am trying to replicate the behavior on my server.
jsfiddle:
http://jsfiddle.net/46XSv/
You want to check the option "no wrap - in <head>" which is "Do not wrap the Javascript code, place it in section".
Select "no wrap - in <head>" under "Framework and extensions"
In this page you'll find the description of each of the options around the bottom: http://doc.jsfiddle.net/basic/introduction.html.
Also its a good practice to include semicolon at the end of your return statement, like the following:
<input type="submit" onclick="return doSomething();" value="click me!">
You should use onsubmit on the <form> element instead of onclick on the <input> element. It will work correctly.
Was wondering how I can reload an iframe every x seconds, perferably not using javascript.
Thanks.
With a Refresh: x HTTP header or with an HTML element in the document loaded into the iframe:
<meta http-equiv="refresh" content="x" />
This element should be placed inside of the document's <head/> element.
If you do not have control over the document loaded into the frame or the server that it is served from, you have two options:
JavaScript.
Write another HTML page with the above <meta/> element and include an iframe in that page targeting the other page. So you will have an iframe inside an iframe: outer document -> iframe(inner document with meta-refresh) -> iframe(original iframe target)
EDIT: Regarding option #2, here's a decent generic iframe in PHP that gives some flexibility in terms of refresh time and style. Just call it with something like:
http://www.mydomain.com/genericIframe.php?url=http://my.domain.com/mypage.htm&refreshTime=60&style=putYourStyleAttribHere
Here's the PHP/HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Generic Iframe</title>
<meta http-equiv="refresh" content="<?php print $_REQUEST['refreshTime']; ?>" />
</head>
<body>
<iframe src="<?php print $_REQUEST['url']; ?>" style="<?php print $_REQUEST['style']; ?>"></iframe>
</body>
</html>
I pass a string from one page to another page using AJAX method.This string is available in the data base.It retrieves string along with the whole client page script of the page from where i am retrieving the data.I want the string alone from the rest of the data using javascript.The string which i retrieve from the data base alone will be keep on changing
This is how it looks:
**live its live** <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"> <head><title> Untitled Page </title>
I want to remove the whole paragraph except **live its live**.The problem is that the **live its live** text alone will be changed if it is updated in the data base
Can anybody pls help me sort out this problem....
demo
var str = '**live its live** <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><title> Untitled Page </title><link href="App_Themes/Modern/default.css" type="text/css" rel="stylesheet" /></head> <body> <form name="form1" method="post" action="/Web/MessageDisplay.aspx" id="form1"> <div> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJNzgzNDMwNTMzZGTa4056JeZHQioLQvNmbYjBQvHt8A==" /> </div> <div> </div> </form> </body> </html>';
alert(str.slice(0,str.indexOf('<!DOCTYPE')))
Your code must have a way to uniquely identify the live its live text to avoid loopholes. If you just slice the string using the content it may fail. Assuming that you used "**" as a wrapper to uniquely identify the text, an alternative to slicing the string or getting its substring is to use javascript's regular expression.
E.g.
var re = /\*\*.*\*\*/gi;
var str = '**live its live** <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"> <head><title> Untitled Page </title>;';
alert(re.exec(str)[0]);
For more information on RegExp, see https://developer.mozilla.org/en/core_javascript_1.5_guide/regular_expressions