I am trying to pass a get variable within the same html page as the page is created in jquerymobile.js
The html contains various internal pages as provided below. Now i want to pass get variables to other page within the same html as id='page1', id='page2' etc. Can anybody help on how can i pass get or post variable within the same html?
decodeURI(getUrlVars()["type"]) is not working in this case since the data is being passed using id over page (id='page2')
Here is the code:
//Page 1 within the same HTML
<div data-role="page" id="page1">
<div data-role="header" data-theme="b">
<h1>Page1 Header</h1>
</div>
<div data-role="content">
//dynamic server content displayed here
</div>
<div data-role="footer" data-position="fixed" data-theme="b">
</div>
</div>
//Page 2 within the same HTML
<div data-role="page" id="page2">
<div data-role="header" data-theme="b">
<h1>Page2 Header</h1>
</div>
<div data-role="content">
//Want to get some of the individual dynamic content displayed in page1 using get method in JSON
</div>
<div data-role="footer" data-position="fixed" data-theme="b">
</div>
I am trying to pass get variable as Button which is not working.
Use following function to get the parameter value
function getParameterByName(name, url) {
if (!url) {
url = window.location.href;
}
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
Related
I store an html string into var HTML, which I get using the following:
var HTML = $('.group').get(0).outerHTML;
The output of HTML using console.log(HTML) is:
<div class="group">
<div class="class1">
Data123...
</div>
<div class="class2">
<!--I want to insert text here -->
</div>
</div>
Now, I want to insert some text inside the div class="class2". I am using the following code:
$(HTML).find('.class2').text("Hello!");
But now the output of HTML using console.log(HTML) is the same old HTML as before. The text "Hello!" did not get inserted. Can anyone help with the solution.
Here is the complete code:
<div class="group">
<div class="class1">
Data123...
</div>
<div class="class2">
</div>
</div>
<script type="text/javascript">
var HTML = $('.group').get(0).outerHTML;
$(HTML).find('.class2').text("Hello!");
console.log(HTML);
</script>
You're updating a temporary DOM element, but that doesn't change the HTML string. You need to save the DOM elements in a variable.
var new_div = $(HTML);
new_div.find('.class2').text("Hello!");
console.log($(new_div).html());
I have a pure css3 modal call by a link, and I wish to pass some variable to the modal.
Modal
<div id="reasonmodal">
<div class="modal-content">
<div class="header">
Reason
</div>
<div class="copy">
//content
</div>
<div class="footer">Close</div>
<br />
</div>
HTML
//some other code with foreach appid
Click
I want pass foreach appid to the modal, any suggestion to do that ? Thanks
i have an idea (js only):
<a href="#reasonmodal" class="modal-link" rel="<?=$app_id?>" >Click</a>
Close
and modal action :
$(".modal-link").click(function(){
$("#submit-link").attr('href','?r=Register/UpdateReason&appid='+$(this).attr('rel'));
$($(this).attr('href')).modal('show');
});
Just print the var
<div id="reasonmodal">
<div class="modal-content">
<div class="header">
Reason
</div>
<div class="copy">
//content
</div>
<div class="footer">Close</div>
<br />
</div>
I see that you want to dynamically pass variables to the model each time click the html div.
Just use ajax post to get these values and update the modal content before it is triggered
Modal
<div id="reasonmodal">
<div class="modal-content">
<div class="header">
Reason
</div>
<div class="copy" id="modal_content">
//content
</div>
<div class="footer">Close</div>
<br />
</div>
Add a onclick event to html div
<a href="#reasonmodal" onlick='updateModal()'>Click</a>
Implement the updateModal() function which will POST an ajax request to get data. Something like this:
function viewDetail()
{
$.ajax({
type: "POST",
url: <?php echo "\"" . Yii::app()->createUrl('controller/action') . "\""; ?>,
data: { param : "value"},
}).done(function(msg){
//update the model content with msg responded from server
document.getElementById("modal_content").innerHTML = msg;
});
}
The modal will be triggered after the html content is updated.
(Give me a vote-up if it works for you)
I have some trouble. I am using this plugin "angular-masonry" (it's on Github) to dynamically build the grid on the page. When the page loads I get this:
http://joxi.ru/YBQPVP3JTJCwfIgLgbc
Here is my code:
<div class="container" style="width:80%">
<h1 style="text-align: center; margin-bottom: 40px">
Category: {{category.text}}
</h1>
<div>(masonry='' load-images="false")
<div class="masonry-brick" ng-repeat="portal in category.claim_portals" style='width:50%;float:left'>
<div>
<h3>(style='margin-left:30px')
Portal: {{portal.text}}
</h3>
<div class="category-list" ng-repeat="claim in portal.portal_claim" style="margin-bottom:2px">
<div class="claim_sections">
<claimforlist claim="claim"></claimforlist>
</div>
</div>
</div>
</div>
</div>
</div>
But after resizing browser window, everything becomes normal and looks like this:
http://joxi.ru/iBQPVP3JTJCUfLnoqQQ
I think that view loads earlier than JSON data arrives.
Can anyone help and tell me how can I load view after the data has arrived? Or if you know another reason of such an issue, please reply.
Thanks in advance.
You can add a scope boolean variable with value set to false, and change the value to true on your http promise success.
Code sample:
function myController($scope, YourDataServer) {
$scope.dataLoadedSuccessfully = false;
yourDataServer
.query()
.$promise
.then(
function(result) {
$scope.dataLoaded = true; // set the value to true
});
}
HTML would look like:
<div id="loadingBar" ng-show="!dataLoadedSuccessfully">Loading data...</div>
<div id="dataWrapper" ng-show="dataLoadedSuccessfully">
<!-- data goes here -->
</div>
I'm currently having problems outputing data in angularJS from a JSON.
I'm pulling JSON from SoundCloud to show song titles. Here is my app:
(function() {
// define the app
var app = angular.module('PartyPlayer', []);
// create the song lister controller
app.controller('SongListCtrl',
function ($scope, $http) {
$http.get("http://api.soundcloud.com/tracks/13158665.json?client_id=MY_CLIENT_ID").success(function(data) {
$scope.songs = data;
});
});
})();
and I'm trying to add the data here:
<div class="row" ng-controller="SongListCtrl as songList">
<div class="small-12 columns">
<div class="list">
<ul>
<li>{{songList.songs.title}}</li>
</ul>
</div>
But nothing shows up. When I console.log(data.title) I get the correct result, but not when I go to add it to my controller in the html. Anyone know the reason why this is happening? Any help would be gratefully appreciated! Thanks!
You have set a scope variable as songs and referring it in the html markup with songsList.songs
Your actual HTML Markup should be
<div class="row" ng-controller="SongListCtrl as songList">
<div class="small-12 columns">
<div class="list">
<ul>
<li>{{songs.title}}</li>
</ul>
</div>
Creating a game where the user answers 5 questions. I want to display their score on a separate page when then complete the game.
This is how my page is set up:
<div data-role="page" id="displayScore">
<div data-role="header">
<h1>How Did You Go?</h1>
</div>
<div data-role="content">
<p id="displayScore" align="center"></p>
<input type="button" value="Play Again?" onClick="startGame();"/>
<input type="button" value="Main Menu" onClick="" />
</div>
<div data-role="footer">
<h4>AL</h4>
</div>
</div>
</body>
</html>
This is my function:
function score()
{
ans += "You scored <strong> " + score + " </strong> out of <strong> " + count + "!</strong>";
document.getElementById('displayScore').innerHTML = displayScore;
}
if you want to pass value to another page then you have to do one of the method between the following methods
pass the value by query string (using get method)
pass the value by post method
use cookies, localStorage or sessionStorage to store the value and retrieve the value in the another page.
if you want to open up a new window the the code will be like this
window.open('http://www.google.com','GoogleWindow', 800, 600);
if you want to create a new window with dynamic value then
<html>
<body>
<script>
myWindow=window.open('','','width=200,height=100');
var displayScore = "your score";
myWindow.document.write("<p> + displayScore + </p>")
myWindow.focus();
</script>
</body>
</html>
it is the best way to directly open the new window with score.
if you have a result.html page then you can pass the score by query string or you can write the javascript code in the result.html page to access any of the cookies, localStorage or sessionStorage to get the score. but make sure you have saved your score in any of it.