I want to call a javascript pop up onsame page by clicking hyperlink , called pop up should be a form not any alert message.
Below is the code for hyperlink on which I want to call javascript:
<a href="#" id="mylink"
onclick="display(document.getElementById(${legList.ledgerId}).value);
return false">${legList.ledgerName}</a>
The above code is working fine but printing as a alert message.I am unable to get pop up as a form.Please help me with the code javascript which gets called on clicking hyper link and that pop up should be a form including some text fields for example reference.
Thanks in advance.
I think the problem is down to your browser blocking popups. For example, the following works for me in Firefox developer edition:
<a target="popup" onclick="window.open('', 'popup', 'width=500,height=200,scrollbars=no,toolbar=no,status=no,resizeable=no,menubar=no,location=no,directories=no,top=500,left=500')" href="http://www.your-site.com">Link</a>
Related
I'm working on automating a task (filling a form and submitting data then getting the result message where the data is being read from a txt file line by line).
While running my JS code via the console, everything works fine until before the clicking on submit button. after the click on the submit button, I can see the HTML is being reloaded with new data and the URL is changed from www.example.com to www.example.com/requests/12345 and then the next step after the click is not respected.
I thought may be because I was using:
document.getElementByID("btn-submit").click();
and changed it to
$("#btn-submit").click().trigger('change');
But still same issue.
I tried to use sleep functions and setTimeout to wait for the new HTML to load but this didn't help at all :(
The task is simple steps until button click all works perfect, I'm stuck only at after the submit button as I want to get the results that shows on the page after clicking the submit button.
Any ideas please what is being done wrong from my side?
The Elements I'm trying to get are in a div that is empty before the submit button is being clicked like this
<div id="message-bar">
</div>
After the submit button is clicked it is filled like the below (also the URL is changed to something link www.example.com/requests/12345 - of course the result elements won't show if the button is not clicked:
<div id="message-bar">
<div id="alert-success" class="alert alert-success">
<button type="button" class="close" data-dismiss="alert">×</button>
<div class="text alert-text">Request approved!</div>
<ul id="bullet-items"><li>Thank you</li></ul>
</div>
</div>
I tried to check if the element is not empty, then get the elements innerText, but seems like my code is being removed when the page URL changes after the submit button:
if (document.getElementById("message-bar").innerText != "") {
// do something
}
Thank you so much
Try
$("#btn-submit").click(function(event){
event.preventDefault();
})
Or without jQuery
var btn = document.getElementById('btn-submit');
btn.addEventListener('click',function(event){
event.preventDefault();
})
Try using the .preventDefault() event
https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault).
From what I understand you need the content not after the click, but after what the click is triggering. Here’s the same Q, answered. Basically you wait for the mods to happen then “read” the element content.
to fix my issue, I thought of using window.open("URL") by creating a variable for it and then using it to process my the whole automation process on the new window and I was able to get all the result message from the new window
var newWindow = window.open("the URL");
newWindow.$('input[id="input"]').val("1234").trigger('change');
etc...
i made form in mailmuch and got code from it , i added to webpage and its working with href , when user click show popup the form is showed. which is ok
show popup
however now i have ajax request and i want this popup to be showed on ajax return success
<a href="#" onclick("getdata(4)")>show popup</a>
so any idea how to do it , because the form is rendered from mailmunch side although if it was in my webpage i should have used simple
$('#popup_id').show();
so how to handle this problem , thanks
Without knowing anything about how mailmunch code works I will assume that all you need to do is trigger a click on the first link within your ajax success:
$.post(url, data,function(){
$('#mailmunch-pop-123').click();
})
Without more code provided it is hard to help more
I have to change my code a little bit to add jquery popup window.
So far I just open new window using:
<a href="?action=_edit&_code=code"><img src...
In new version I simply open popup window using:
<a href="#myDialog" data-toggle="modal" onclick="">...
It works in terms of open dialog box, the only problem remains is how to pass arguments from ?action=_edit&_code=code in this case ?
Thanks for help ;)
You can use more data tags, for example, data-action, and data-code. These can then be obtained in your on click handler.
This link here might give you a better idea: http://www.slideshare.net/lensco/html5-data-attributes
i have link
<a onclick="return package_tour_order(14400287396);" href="javascript:;">advanced</a>
<a>doit</a>
need to get value from onclick only ID nubmer, but this
return package_tour_order(14400287396) is javascript function that popup new window with informationabout that ID
if i run this code
$('a:contains("advanced")').attr('onclick').match(/\d+(?=\))/)[0]
it works fine but when i run in my project with that javascript function(this function is loaded from another site) its does not work and popup window
i need to disable onclick somehow and get only that ID number, how can i doo that?
Don't make it a link. Make it a span or whatever. Also... what do you mean by "function is loaded from another site". If the script is loaded that should not influence things.
What is target="_new"? Validator is raising an error..
How do you do this with jquery because Validator is raising an error.
On the same page, I have target="_new" and target="_blank". target="_new" is in that form code which i received from email newsletter company.
I'm using this for target="_blank"
$(function() {
$('a[href^=http]').click( function() {
window.open(this.href);
return false;
});
});
What should i do for target="_new"
Update: 1 min Ago
upon clicking on submit button i want to open a page in new window to pass validation how to do this in jquery as i'm doing for other external link.
update:
this is code
<form method="post" class="form-wrapper" action="http://sitename.com/form.php">
There is no such thing as target="_new". Using this will simply open the link in a new window called "_new". You might notice that clicking on a link with target="_new" will open a new window (or tab) but then a second link will open in the same window (or tab), rather than opening a second one as you'd probably expect.
Personally, I don't think you should be specifying target="_blank" at all - let the user choose.
target="_blank" is invalid in XHTML (actually, the entire target attribute is invalid). If you want a link to open in a new window (usually a bad idea, in my opinion) and validation is important to you, the only way to do it is with javascript (like you did).
This is an attribute for a(anchor) tag, which let you open the page on the same window or in a new window.