Html5 localstorage between two pages - html

Am trying to make a game using Html5. my need is i have menu html page with 3 buttons one,two,three. when am clicking on that button am storing that value like one or two or three storing in a variable and it'll go to next page game.html. and i can retrieve it too.
localStorage.setItem("value",$(this).val()); //storing 1,2 or 3 in value
var value_menu = localStorage.getItem("value"); //getting value in value_menu
here i have a back button in game.html page, if i click on that it'll go to menu page and am removing the key values from localstorage.
localStorage.removeItem("value"); (or) localStorage.clear();
if am again click on the buttons in menu page, the value showing as null. why its showing as null ? because if i click on button the localstorage have to store value again. isn't it?
otherwise am making any mistakes? need some explanations.
thank u in advance.

Because null is the default value when something does not exist and you delete the value when yo go back so it is "logic" .... the value is null because it does not exist because you remove it.
Okay? ;-)
You can interpret null as 'not selected' (in your case it IS not selected and that's true because you have deleted it when the user go back). The next thing you have to do is to check if the value is null (value === null) and to do nothing when it is null (not showing it). Or much better: if( typeof value == "number" && value > 0 ) etc.
It think it is better to not remove the choice of the user until the user left the first/entry page.
Pure interest: What kind of game do you want to create?

Related

passing cascade dropdown value to Gallery on next screen, PowerApps

I'm doing POC on PowerApps and need help and advice
I connect my app to Excel as data source, ~ 800 records. I intend to pass these cascade dropdown value to my next screen in order to filter my Gallery displaying bunch of data. But I got no value in my Gallery.
Then i continue my experiment to test passing value with Label. I formulate my Next button in passing ONE dropdown value to next screen -- Navigate(Scr_Result,ScreenTransition.Cover,{selectedSite: drop_assetsite.Selected.Result --, i successfully get that value. But when I combine those 3 dropdown value on my NAVIGATE function, i got FALSE on my label text instead
Here is my NEXT navigate formula --- Navigate(Scr_Result,ScreenTransition.Cover,{selectedSite: drop_assetsite.Selected.Result And drop_building.Selected.Result And drop_assetcategory.Selected.Result}) But i found no red X mark on my NEXT button.
I'm not quite sure that I can combine those cascade value in one argument on Navigate or not. I can't find this combination somewhere. Thanks in advance for all replied. ^_^ and sorry for my poor English
You can use an expression like this one:
Navigate(
Scr_Result,
ScreenTransition.Cover,
{
selectedSite: drop_assetsite.Selected.Result,
selectedBuilding: drop_building.Selected.Result,
selectedCategory: drop_assetcategory.Selected.Result
})
And in Scr_Result you can access the three values (selectedSite, selectedBuilding, selectedCategory) in any expressions on that screen.

When the Switch Input is off, it returns NULL element?

I have array of Krajee SwitchInputs, when everyone of SwitchInput is off, it returns nothing.
SwitchInput::widget([
'name' => 'work_time[]',
'value' => 1,
}
The reason you won't receive the values
This should be expected behavior (empty checkboxes are not considered "successful") and has nothing to do with the actual kartik-widget. In the background the widget uses a regular checkbox.
To save overhead, empty checkboxes won't transmit "0". So when you have more than one and all are off, nothing will be transmitted. However this is no problem as you know when all are missing, all are off!
You can find a lot of similar questions here, like this one for example, explaining the same thing. Don't worry too much, as it is quite simple:
value missing or 0: individual checkbox is off
all values missing: all are off
If you still want a workaround, you can find one here
Checking the right way
The following code will respect the types when comparing. Normally you would use either a boolean value or 1 and 0 as integers. Both work perfectly, but the boolean-way is better, as you are then not only able to use the equal-operator == but also the identical-operator ===.
$myCheckboxVal = isset(Yii::$app->request->post('my_checkbox')) ? true : false;
Thanks, I solved.
$value=isset($_POST['day_check']) ? '1' : '0';

ms access dynamically adding textbox for amount of goals

Good evening,
I'm completely stuck in ms access, trying to create dynamically added fields.
I've got a form called frmMatch.
It contains 6 fields called:
MatchDate - Date field
CompetitionType - ComboBox
Location - Input field
TeamName - Input field
ResultHome - Input field
ResultAway - Input field
Now what I would like to create is just a simple button called something like Add Scored Players
The problem is, I have no clue on how to get VBA to run through the ResultHome field if it is a Home game or through ResultAway if it is an Away game.
For example when a home game end up with a 3-1 win I would like VBA to run through a loop until it hits the ResultHome value, in this case 3.
And adds the amount of text box in according with the ResultHome value.
So I can put in the names from a combobox or textbox and the time he scored.
I hope you guys can help me out with this.
Ive searched on this form as well as other website but I cant find anything that would help me.
What you need here is not to "add textboxes", but rather to make them visible.
So, what you'll need to do is to create all your textboxes and set their Visible property to "False". Name them with numbers, like "tbScore1", "tbScore2", "tbScore3", etc...
Then, you'll need to add some VBA behind your button to make the proper number of textboxes visible. Something like:
'If both scores are 0, no need to show anything
If ResultHome.Value = 0 and ResultAway.Value = 0 then
exit sub
else
'Otherwise, set the value of the loop to whatever the score is
If ResultHome.Value <> 0 then
LoopVal = ResultHome.Value
else
LoopVal = ResultAway.Value
endif
endif
'Make as many textboxes visible as necessary
For i = 1 To LoopVal
MyFormName.Controls("tbScore" & i).Visible = True
Next
Note: this is all "aircode" and is not tested, so it may require some tweaking to make it work. But this is the logic structure you can use to achieve your results.

<%#Eval %> in asp.net to move page

Like other 'List' page, I'm making a <a> tag on td, and 3buttons 'Go up','Go down','Go list'.
I succeed after click this link, go another page.
<%#Eval("Title")%>
Now, the problem is here. To make Go up/down pages, I guess put the number +1 on the link to calculate page number.
<%#Eval("Title")%>
Then, when I check address, result just show +1 not calculate.
//address : http://localhost:61375/NoticeDetail.aspx?seq=+1
How can I calculate on Eval Databinding data and show that? or, do you know how to make a function up/down page with Eval?
If you have a string value in the database and you expect it to always be an integer and it shouldn't be null, then you should use int.Parse()
<%#Eval("Title")%>
Otherwise if you don't know the type of data and you don't sure about the null values then should use Convert.ToInt32(). Convert.ToInt32() returns 0 for null, while int.Parse() throws a ArgumentNullException
<%#Eval("Title")%>
You're not parsing the int, try this (if your int is nullable though, make sure you check for that first):
<a href='NoticeDetail.aspx?seq=<%# int.Parse(Eval("Seq").ToString()) + 1 %>'><%#Eval("Title")%></a>

Displaying selected OPTION in HTML dropdown menu on refresh, not value - possible?

My drop down menu has genres that it displays, but numbers as the values, eg
<option value=240>Alternative Rock</option>
My POST data deals with just the value - that's all I need for my database, and it works fine.
However, I'd like to display the selected option after submission, which I would normally do like this if the option and value are the same...
if ( isset($_POST['genre']) && $_POST['genre'] != "" && $_POST['genre'] != "undefined" ) echo stripslashes(htmlentities($_POST['genre'])); else echo 'All';
But since they are not the same, after submission the above example now displays "240" as it's selection, not "Alternative Rock".
How do I get it to remember the display option, not just the value, while still getting the numerical value that my database queries need?
Thanks for taking a look.
The POST is not going to include the disable value by default. There are a couple options... You can store all the options on the server side while the original page is being created (for example, in a session variable), and then look up the display value when the POST comes in. Or you can use JavaScript to set a hidden form element with the display value, when the user submits the form.