Simulate button click with loadContent - javascript

Right now when user want to go back they are required to click a button. Here is the code that generate said button :
echo "<button onclick=\"loadContent('client/profile_edit.php?id=182&next_tab=user_records');\" value=\"Back\" type=\"button\" class=\"negative iconstxt icoNegative\"><span>Back</span></button>";
Now I want to make it automatic. I want it to redirect automatically. Is there anyway I can simulate button click with PHP? JavaScript redirect does not work mainly because I have problem with this part client/profile_edit.php
It's a PHP page inside a page. I'm sorry because I don't know what it's called. Maybe it's a frame?? The redirect code below partially worked:
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.location.href='client/profile_edit.php?id=182&next_tab=user_records';
</SCRIPT>");
I do get redirected to client/profile_edit.php but there's no CSS at all. That's mean a page with no styling.
So anyone know how can I simulate button click? Please comment if what I'm wrote does not make any sense/clear. Thanks in advance.

Related

Bootstrap spinner-border disappear

currently I try to make website which should print some line after I click a link.
So far so good, now I want to add a spinner-border from bootstrap. It works pretty well but I have no idea how to remove it again.
<p>New here? Sign up here.</p><br>
<?php
if(isset($_GET['signup'])) {
echo '<div class="spinner-border" role="status"></div>';
for($i=0;$i<3;$i++){
flush();
ob_flush();
sleep(1);
}
echo "<span><h1>Sign up</h1>";
So I think what you're trying to do isn't really something you'd want to use PHP for.
Please correct me if I'm wrong, but it looks like what you want is:
Show a page with a link to a sign up form
When you click the link, show a spinner
Hide the spinner after a second, and show the Sign up page
PHP can't be used to create a dynamic page like this, as it executes all of the code on the server, before sending it to your browser.
Really, if what you want is a link to a sign up page, all you need is a separate file instead, as then you can link to that and when you click it, the new page content would be there.
However, if you want to use the spinner, things will get more complicated as you would need to use some ajax to load the page content.
Alternatively, if all you want is a spinner to show before showing the content, you could let the page reload as normal, showing the spinner. Then hide the spinner using JavaScript.
If you had your spinner-border class, you could do something like
document.getElementsByClassName('spinner-border').style.display = 'none';

Google Tag Manager Form - Thank You Page

I am trying to use google tag manager to have a tag that will fire every time the user submits the form and lands on the thank you page. In this scenario, I know an option is to use the Trigger: Page View, and then specify the thank you page URL in the conditional statement.
However, since this URL can be shared, I only want to track when the user submits the form and lands on the thank you page (not when the URL is accessed through other ways). What would be the best way to tackle this?
Why would people share the thank-you page? I can imagine sharing a form, but why would the url of the Thank you page get shared.
However, what you can do is track clicks on the button or link that submits the form.
I ll advise assuming you NEED to fire when the user gets to the ThankYou Page for X reason and CANT be done on the button submit click.
Add a custom HTML tag with a trigger on the click of the form submit button (you can use build in variables such as Click Classes) and add a 'flag' on the session storage or a cookie (choose the one you are more comfortable with).
Then generate a trigger that fires on the Thankyou page AND has the flag on.
Example:
Tag when user submit the form:
<script>
storage.setItem('flagSubmit', 1);
</script>
Custom JS variable that checks if user has flag:
function(){
return storage.getItem('flagSubmit');
}
If you need any more help just ask.
Hope it helps!
-- EDIT: add info
As you comment you cant detect if the flag is being saved properly so here is a code you can paste on the console that ll avoid you browser to exiting the page and allowing you to see if your click tag worked and registered on session storage you data.
window.addEventListener("beforeunload", function() { debugger; }, false)

Can we open A hidden tab or window and submit the form automatically on that tab/window?

I have a form where I add user in to my Application.
Once the form is submitted I want to open a hidden TAB/WINDOW.
On the new opened tab I have another form in which I have some values frmo database which i write to a file, So I want to this form submitted automatically. I want this process as background so user does not know about this.
Currently when user hits the submit button a record is inserted/updated into database and then he gets redirected this way:
<script>
var id = <?php echo $data['base_ini_id']; ?>
window.open("./edit_ini_custom/"+id+"/"+<?php echo $data['ext']; ?>);
</script>
How do I redirect him in background and submit the form at the URI : ./edit_ini_custom/
The method you want to use is a bit dirty I think. Take a look at Ajax, learn it, try it, it was made for this type of request.
You can use Ajax with vanilla JS like here.
You can use Jquery too like described here.

Prevent refreshing the page after button clicked in vb.net

I have a page with a javascript that dynamically create a controls (radio buttons, text boxes) .
on button (submit) I need to validate the values before proceeding with the event it self .
but , after hitting the button I need to cancel the event if one rule didn't obey. but the page gets refreshed and all my dynamic controls goes so I need to stop any action to a page if one of the rules failed . (save the form)
I believe there is a way such as e.preventDefault(); in javascript .
Please Advise,
Many Thanks :)
There are many ways to prevent page refresh But we are not certain what you are talking about, so I'll just Give the regular example That I can Find
Fist your e.preventDefault is not for refresh its just prevent link from opening the URL and i.e as per w3school
$("a").click(function(event){
event.preventDefault();
});
Now To prevent a page refresh there are too many example Please take a look at the Given link Please take a look

If user clicks on one link then quickly on another, the second link's onclick doesn't fire. How do we avoid this?

Apologies for the title, I found it hard to define my question succintly and that was the best I could do. If someone wants to edit it to add a better title then please, be my guest.
Anyway, the question. We have on our webpage the capability for users to delete something. They do this by clicking on a delete link, something that looks something like:
<a href="http://localhost/a/path/remove-thing.html?ID=42" onclick="return confirm('Are you sure you want to remove this thing?');" >Remove this thing!</a>
Now, obviously, normally when the user clicks on that link they get a javascript confirm box which asks them to confirm that they want to delete the thing. If they click cencel, the onclick event is false and so the delete doesnt happen; if they click okay then it does.
My problem is that if the user clicks on another link in the page (to anywhere), then quickly clicks on the delete link before the first page loads, the javascript never gets fired, but the thing is deleted - when they clicked on "Remove this thing!" they fired off that URL instead of the one they originally clicked. Is there a way to avoid this? Are we doing the confirm 'wrong'? I assume it has something to do with the browser shutting off the javascript checking when you click the first link as it prepares to render a new page, but then still accepting a change in URL before the page has gone...
(This has been tested in Firefox 3.6 and confirmed a problem there. No other browsers tested yet.)
one way around this which would degrade a bit more gracefully would be something like:
create a separate confirmation page which these links send you to
use javascript to show the dialog, and if 'yes', send the user directly to the delete page
this way it works even without javascript, and should hopefully eliminate your issue
EDIT
if js will always be present, you can always have the default link be empty, and redirect the user after confirmation
You're really having a couple of problems. I think you would be better off taking a progressive enhancement approach.
What happens to your users if they don't have the JavaScript? I know that people rarely turn off JavaScript, but it's still a useful thing to consider. Without JavaScript, people will be deleting items without confirmation.
You're better off linking to a delete form that asks "Are you sure you want to delete X?" and has "Delete" and "Cancel" buttons. After the form submits or they press cancel, you can send them back to the original page. *
Now for the progressive enhancement: attach a click event handler to the "delete" link that pulls in the "are you sure?" form via AJAX or builds it from scratch. Have the form replace the delete link. If they click the "Delete" button, just submit the form as before. If they click cancel there's no need to reload the page - just remove the form and restore the original "delete" link.
* as an aside, make sure the form is a post form and that it has CSRF protection. If you don't know about CSRF attacks, definitely read up on them.

Categories

Resources