I'm using the following jQuery in a Confluence page (using code that allows you to insert HTML in Confluence pages) to fill some fields in an external HTML page with what users enter into input fields.
Now I want to change it to use the post method instead of get.
Here's the code: First, assign an ID called input2 to a built-in Confluence input field:
$( document ).ready(function() {
$(".search-macro-medium .search-macro-query input").attr("id","input2");
});
Then, the code that appends the input to the URL:
$( document ).ready(function() {
$('#srsButton').click(function(e) {
var inputvalue = $("#input2").val();
if
($('#input2').val()==""){
$('.alertReq, .asterisk').css('visibility', 'visible');
}
else
window.open("http://ift.tt/1CxDp2q"+inputvalue);
});
});
This all works, and I also know how to use post in a form that I create, like this:
<form style="margin-bottom:200px" action="http://ift.tt/1GuRWen method="post">
Confirmation <input type="text" name="F_334133"><br>
Subject <input type="text" name="Subject"><br>
<input type="submit" value="Submit">
Combining the two is puzzling me though. Maybe it's simpler than I think.
The main thing is that I can't create my own form, but need to pick up what's inserted in the .search-macro-medium .search-macro-query input form instead.
UPDATE:
Putting this here to not clog up comments:
Thanks for the responses. I could possibly sell people on going back to having it in the same window, what's more important is that I can't just create my own form but have to use this field that's inserted in the page by a Confluence "macro".
I have to style and manipulate these dynamically as they load on the page, identify the elements and so on. For example .search-macro-medium .search-macro-query input is actually a search field that I'm using to do two things: One being the built-in Confluence auto-suggest functionality that will drop down a list of suggested links, and the second being that I pick up what the user enters into it and use that to populate a form elsewhere.
I could re-create the entire input field but then I'd lose the auto-suggest functionality. Kind of a hybrid world, creating some of the HTML myself but having to rely on these little widgets also.
Oh and yes, I have no control over the destination page; same company, but -- would be complicated to get it changed.
UPDATE II
I'm accepting Arkantos' answer because I basically used the hidden form idea to make this work, though in a slightly different way. For the other part that I mentioned, capturing text from the built-in Confluence dropdowns, here's the code that worked including the .clone().append(' | ').text()); part that allows me to get all the drop down li text, post it in a form field, and insert separators in the list.
// Show the suggested match heading when anything typed in field
// Capture dropdown titles
$( document ).ready(function() {
$('form.aui').on('keyup', showHead);
function showHead() {
$('.suggestHead').delay(500).fadeIn(300);
$('.alertReq, .asterisk').css('visibility', 'hidden');
var dropdownText = (AJS.$( "div.searchContainer2 a.content-type-page span em" ).clone().append(' | ').text());
$('#capture').val( dropdownText );
var inputvalue = $("#input2").val( );
$( '#describe' ).val( inputvalue );
};
});
Aucun commentaire:
Enregistrer un commentaire