I have 2 pages
HTML page with a form
PHP action page for the form
Based on this, if everything is successful with the form submission, I want to go back to the first page and open up a modal using document.getElementById.
I know to do this, I would need the header("Location: blabla") function in my PHP page to go back to the first page, but how am I supposed to open up the modal after getting to that page?
Any help would be appreciated, thank you very much.
It is better to use ajax in this case, yet if you have to do it this way you can use the query prams, for example you redirect the user to your html page like this
header("Location: blabla.html?m=some message to show")
then in your html page, you need to check if this param exists then display the modal like this
searchParams = new URLSearchParams(window.location.search);
if (searchParams.has('m')) { // searchParams.get('m') then open the modal or do what ever you want. }
edit: you can use any other param instead of the message, it could be what modal to show, or whatever
Related
I have a simple html form which contain 2 fields and submit button. After hitting submit button my data transfer toward the another server through query string named "http://www.123contactform.com" which is load in iframe on my page and the field which is in the iframe become pre-populated with the information coming from query string. That's All I have done.
Now what I want want when the submit button of iframe click, the page transfer towards the another page, I want to restrict that navigation and define my own url with javascript.
Can any one help me, How do I get this???
Regards,
Ammar
Can you show some code ?
And
Logically What you want is something like this - You have an iframe on example.com and that iframe load's gmail's login page, You want to change the submit url of gmail's login form ?
NOT POSSIBLE
So, I want to change the display style of one of my divs, here's the code in my javascript:
document.getElementById("header1").style.display='none';
Now the problem... header1 is a div id on a different page, but I want to affect that from selecting an option on the current page. How do I go about doing that so that the header1 will be hidden when I go onto the next page?
Thank you in advance!
You cannot change the properties of an element that has not been loaded into the browser yet. You would have to use a cookie or the querystring to tell you to hide the element when the page is loaded.
Edit
You can redirect to a new page using the following javascript. Note: everything following the ? is part of the querystring.
// Redirect without querystring
window.location = "http://www.mySite.com/default.html"
// Redirect with querystring
window.location = "http://www.mySite.com/default.html?hide=true"
// Redirect with multiple values in querystring
window.location = "http://www.mySite.com/default.html?hide=true&test=1"
Check out get-query-string-values-in-javascript to see how to retrieve querystring values through javascript.
You could pass the value to the next page in a hidden form field or possibly via the url then when that page loads use that value to set the desired value on the page.
how about carrying the value/selection to the other page using local/session storage, or even indexDB, if you have a lot of information to carry or you are carrying across multiple pages. saves having unneeded POSTS and removes the need for any server side code
when user register successfully then action attribute of registration form redirect him to login.html. I want to change a div text for informing him that his registration is successful. I can't understand that how can change div text after redirect.
You cannot change text on another page unless you have script on that page for that purpose.
You are better off using server-side code to change the message. For instance, using php, you would have a login.php page that take a parameter called success, so you would call login.php?success=1 if your login succeeded, and the php script would add the message to the page.
This is just one example of how it might be done, but the key is that you cannot change content on a subsequently loaded page from script on your current page.
Now, if you want to use script, you could use jQuery to load the login.html content into your current page context, using .ajax() or any of the ajax jQuery functions .post(), .get(), etc. Then you can use your script to change the content, because it will be in your current page.
I'm building a site in CakePHP, and I'd like to give a 'Preview' option for pages as they're being added or edited.
In the 'Add Page' view, for instance, I have the usual form which the user uses to create their page. There is a 'Save' button, to save the data. Next to that, I'd like to have a 'Preview' button, which opens the page in a new window.
So, either I need the controller to open a new window (and I don't think this is possible), or it needs to be a link (targetting a new window) instead of a button - but in that case, how do I POST the data so that it can be shown? Do I need to use ajax or something? I'm a total newbie in ajax, but I do have a reasonable grasp of javascript.
Thanks for any help!
If the data that you are previewing is already saved on your database, then you can have an action in your controller (maybe preview()) action that references the saved data and loads the preview. And then to use it, you can just use a regular link that targets a new page and opens it there.
This would require saving the data the user is typing to your server every few seconds, though.
If you want to use the data that is still on the page, then you can use a JavaScript function to load a lightbox and populate the contents of that lightbox with data from the fields that the user is working on. You can probably use fancybox for that.
I have a page where there is a form(and url is xyz.com/form)...
Now when the user submits the data, it should redirect to the home page of xyz.com(url is xyz.com) and then display a message as "Thank you" in an existing div id (div id="message")of the home page...
Is it possible to do it using javascript??
Will I get the value of that div id(message) when the it redirects to home page using javascript.
I could redirect the page to home page.. but couldnt insert contents in that div... or in a new div...
Please help
i would add a GET-parameter to the url like "status=ok". on the main-page you can check this parameter with javascript and change the value ('innerHTML') of the div.
Without having seen your code, i would say yes, it is possible.
On entering the main page you can check the referring page and you could also check some session stored data that validates if the user has submitted the form (i suggest ajax for this).