Place one HTML input directly below another with HTML - html

So I have a bunch of HTML elements I'm creating dynamically. I would really like the element "imageBox" to appear directly below the "mediaBox" instead of to the left of it like it is now. Here is my code right now:
var div = document.createElement("div");
//HTML code for each element to be added with each new checkpoint
var nameBox = "<b>Checkpoint " + markerId + ":</b> <input type='text' id=" + markerId + " placeholder='Checkpoint name'>"
var descBox = "<textarea rows='4' cols='35' placeholder='Checkpoint description' id=" + markerId + "desc style='vertical-align: top;'></textarea>"
var mediaBox = "<input type='text' id='media" + markerId + "' placeholder='paste URL to YouTube video' size='23'>"
var imageBox = "<input type='text' id='image" + markerId + "' placeholder='paste URL to image' size='23'>"
var removeButton = "<button type='button' value='Remove' id='remove" + markerId + "' onClick='remove_marker(" + markerId + ")'> Remove </button>"
var undoButton = "<button type='button' value='Undo' ' style='display: none;' id='undo" + markerId + "' onClick='remove_marker(" + markerId + ")'> Undo </button>"
var removeText = "<div id='removed" + markerId + "' style='display: none;'> Removed <button type='button' value='Undo' ' style='display: none;' id='undo" + markerId + "' onClick='undo_Remove(" + markerId + ")'> Undo </button> </div>"
div.innerHTML = nameBox + descBox + mediaBox + imageBox + removeButton + removeText;
I know it is really messy and ideally I should be using CSS but I'm not right now. It shows up on my page like this:
It would be great if the image URL box could be right under the YouTube one!
Thanks so much!

For minimal re-writing, you can try wrapping the two boxes in an unordered list. If you really truly want to avoid CSS, set an inline style to remove the bullets.
div.innerHTML = (nameBox
+ descBox
+ '<ul style="list-style: none;"><li>'
+ mediaBox + "</li><li>" + imageBox
+ "</li></ul>"
+ removeButton
+ removeText);
I just inserted the relevant bits into your last line. You really really should use document.createElement and div.appendChild to create these things.

Related

Dojo dijit add Div buttons dynamically

I am having an issue with trying to dynamically create layers that can be be built and removed with a div as a button being added upon the layer's creation. Here's how the code goes:
I am having an issue with trying to dynamically create layers that can be be built and removed with a div as a button being added upon the layer's creation. Here's how the code goes:
//build point graphics layer
graphicsLayerInfo = this._addNewExcelLayerToList(plotArray.length);
graphicsLyr = new GraphicsLayer( { id:graphicsLayerInfo.graphicsLayerID} );
this.map.add(graphicsLyr);
on(dojo.byId(graphicsLayerInfo.removeButtonID), "click" , lang.hitch(this, this._removeExcelLayer, {layerID: graphicsLayerInfo.graphicsLayerID, buttonLayerID: graphicsLayerInfo.currentLayerInfo}) );
...
and the function used to build the DIV/button
_addNewExcelLayerToList: function (pointCount) {
if (this.debugMOde) {
console.info( this.name + ' - ADD NEW EXCEL LAYER called.' );
}
this.layerCount++;
currentLayerID = 'graphicsLayer' + this.layerCount;
graphicsLayerID = this.name + '_gLyr' + this.layerCount;
removeButtonID = "removeGraphicsLayer" + this.layerCount;
this.layerList.push(currentLayerID);
var layerInfo = "Number of Features: 1 Line";
if (pointCount) {
layerInfo = "Number of Features: " + pointCount;
}
content = "<div id ='" + currentLayerID + "'" +
"style='width: 95%;" +
"height: 16px;" +
"line-height: 16px" +
"verticle-align: middle;" +
"padding: 5px;" +
"background-color: #000000;'" +
">" +
"<div style='float:left;'>" +
"<div style="float: left;" +
"width: 20px;" +
"line-height: 20px;" +
">" +
"<img src='./js/Upload/images/excel.png'" +
"style='position: absolute;" +
"top: 0;" +
"bottom: 0;" +
"margin-top: -10px;" +
"width: 20px;" +
"vertical-align: middle;'" +
"></img>" +
"</div>
"<div style='float:left;" +
"font-size: 0.9em;" +
"color: #ffffff;'" +
">" +
"Layer" + this.layerCount + ": " + layerInfo +
"</div>" +
"</div>" +
"<div id='" + removeButtonID + "'" +
"data-dojo-attach-point='" + removeButtonID + "'" +
"name='" + removeButtonID + "'" +
"id='" + removeBUttonID + "'" +
"style='float: right;" +
"width: 13px;" +
"height: 13px;" +
"cursor: pointer;" +
"border-radius: 50%;" +
"border: 2px; solid #ffffff;" +
"background-color: #ff0000;" +
"color: #ffffff;" +
"font-weight: 300;" +
"font-size: 17px;" +
"font-family: Arial, sans-serif;" +
"text-align: center;'" +
">" +
"X" +
"</div>" +
"</div>";
layerListDiv.innerHTML += content;
graphicsLayerInfo = {
removeButtonID: removeButtonID,
graphicsLayerID: graphicsLayerID,
currentLayerID: currentLayerID
}
return graphicsLayerInfo
}
and the function to remove the DIV
_removeExcelLayer: function(layerInfo) {
if (this.debugMode) {
console.info( this.name + " - REMOVE EXCEL LAYER called.");
}
this.map.removeLayer( this.map.getLayer(layerInfo.layerID) );
dojo.destroy(layerInfo.buttonLayerID);
}
It removes the layer if I create only one. If I create more than one, only the last layer created gets moved. All the other 'removeButton's don't work.
Any ideas on how to get this to remove the layers individually, per button?
Well, with the help of a coworker, I got it to work, but not with exactly a separate Event Handler. I used a domConstruct to create it's own area of influence:
domConstruct.create("div", { innerHTML: content }, layerListDiv);
instead of the straight:
layerListDiv.innerHTML += content;
Thank you for your attempts ManjunathaMuniyappa.

Angular code inside of html strings

I am trying making the following code working:
var td = $(elem).treegrid('getPanel').find('div.datagrid-header td[field="itemtype"]');
td[0].innerHTML = td[0].innerHTML +
'<table style="width:100%;margin-top:-8px;margin-left:2px"><tr>' +
'<td style="width:18px;text-align:center">' +
'<a href="" ng-click="getFilteredAssets(filterItemType)">' +
'<img border="0" src="all_filter.png">' +
'</a>' +
'</td>' +
'</td>' +
'<td style="width:18px">' +
'<img src="assets_filter.png"/>' +
'</td>' +
'<td style="width:18px">' +
'<img src="projects_filter.gif"/>' +
'</td></tr></table>';
I am getting images into the place, but clicking on the image with ng-click specified doesn't do anything. Any idea how to make it work?
Thanks
Modified code
var element = $compile(angular.element
('<table style="width:100%;margin-top:-8px;margin-left:2px"><tr>' +
'<td style="width:18px;text-align:center">' +
'<a href="" ng-click="getFilteredAssets(filterItemType)">' +
'<img border="0" src="all_filter.png">' +
'</a>' +
'</td>' +
'</td>' +
'<td style="width:18px">' +
'<img src="assets_filter.png"/>' +
'</td>' +
'<td style="width:18px">' +
'<img src="projects_filter.gif"/>' +
'</td></tr></table>')
)(scope);
td[0].innerHTML = td[0].innerHTML + element;
Angular has no way of knowing you've added some HTML to your DOM. You should use a compile service. It will sweep HTML searching for ng-* directives and so on and apply it to current scope.
var element = $compile(angular.element('your html with ng-* directives''))(scope);
Then you can insert that element to your DOM.

remove span by class from $(this).html()

Basically my search returns search results in spans, then when one is clicked, a new span is added to another div with a select input and hidden input so all the selected features can be posted as an array.
My question is, $(this).html() now includes a span of class alias_span. Which I don't want to appear in the new span. How do I remove it before inserting the contents of the clicked span into the new span
$(".minisearch_res").live('click', function() {
// when a search result is clicked we disable the submit button,
// append a span to the left column with an id,
// a select input to select standard/optional and
// a hidden field with the required information to save and something to
// show the user
var id = $(this).attr('id');
var html = "<span class= \"added_result_cont\" id=\"" + id + "_cont\">";
html += "<select name='" + id + "_sel'>";
html += "<option value=\"none\" selected=\"selected\"></option>";
html += "<option value=\"std\">Standard</option>";
html += "<option value=\"opt\" >Optional</option>";
html += "</select>";
html += "<span id= \"" + id + "\" class=\"added_result\">";
html += "<input type=\"hidden\" name=\"selectedfeat[]\" value=\"" + id + "\">";
html += $(this).html() + "</span></span>";
$('#div_apply_to').append(html);
$(this).remove();
$('#search_input').trigger('keyup');
$("input[type=submit]").attr("disabled", "disabled");
});
Update: here's the html of the span
<span class="minisearch_res" id="opt_1">Anti-Lock Brakes<br><span style="padding-left:20px" class="alias_span"><i>abs</i></span><br></span>
<div></div>
Add it to the dom, then remove it.
var htm = (
'<span class="foo">foo</span>' +
'<span>bar</span>' +
'<span>bar</span>' +
'<span>bar</span>' +
'<span>bar</span>'
);
var $el = $("div").append(htm);
console.log($el.html());
$el.find('.foo').remove();
console.log($el.html());
http://jsfiddle.net/chovy/w2HdE/
Got a tidy cross browser solution, which I'm very proud of :)
var temp = $(this);
temp.children('.alias_span').remove();
$('#div_apply_to').append("...html..." + temp.html() + "...html...");
inspiration came from here:
Remove element from Ajax Response

Google maps set width for InfoWindow

Hi I am using InfoWindow to get custom popup on google maps,
but I can't set it width, I tried setting it inline to wrapper tag, but it doesn't work.
In this case I need it to be 750px.
Here is jsfiddle: http://jsfiddle.net/xxast/
and here is html file: http://www.mediafire.com/view/?66dbe6xzn1mul10
Here is method that is setting InfoWindow content:
function getContent(parts, kmlEvent) {
var content = ""+
"<div id='width800' class='google-infobox-content' >" +
"<div class='image'>" +
"<img src='http://maps.google.com/maps/api/staticmap?center=" + kmlEvent.latLng.Ya + "," + kmlEvent.latLng.Za + "&zoom=13&size=150x150&maptype=roadmap&sensor=false&language=&markers=color:red|label:none|48.7758013,9.2529132' title='' width='150' height='150' >" +
"<br />" +
"<a href='https://maps.google.com/maps?sensore=true&daddr=" + kmlEvent.latLng.Za + "," + kmlEvent.latLng.Ya + "' target='_blank' >Full Google Map</a>" +
"<a href='http://maps.google.com/help/maps/directions/Somewhere' target='_blank' >Directions</a>" +
"</div>" +
"<div class='location'>" +
"<p>" + parts[0] + "</p>" +
"<p>" + parts[1] + "</p>" +
"<p>" + parts[2] + "</p>" +
"<br/>" +
"<p>" + parts[3] + "</p>" +
"</div>" +
"<div class='contact'>" +
"<p>" + parts[4] + "</p>" +
"<p>" + parts[5] + "</p>" +
"<a href='mailto:" + parts[6] + "' >" + parts[6] + "</a>" +
"<a href='" + parts[7] + "' target='_blank' >" + parts[7] + "</a>" +
"</div>" +
"<div class='others'>" +
"<p><b>Product line</b></p>" +
"<p>" + parts[8] +
"</p>" +
"</div>" +
"</div>";
return content;
}​
Updated
here is updated jsfiddle with setted maxWidth and inline width for wrapper tag, but still it doesn't work: http://jsfiddle.net/xxast/3/
there is no width in the google.maps.InfoWindowOptions object.
create a div inside your infowindow, and set its width.
the infowindow will resize to fit the internal div.
i have a working example here: http://jsfiddle.net/RASG/vA4eQ/
EDIT
some extra info:
i've found in a google group a very interesting information, written by a google employee.
Info window size is determined based on two factors:
the size of the content
the size of the map (not the browser)
to be free of this, you must implement your own kind of infowindow.
some examples here:
http://gmaps-samples-v3.googlecode.com/svn/trunk/infowindow_custom/infowindow-custom.html
http://gmaps-samples-v3.googlecode.com/svn/trunk/smartinfowindow/smartinfowindow.html
Google v3 Api comes with:
var iw = new google.maps.InfoWindow({ content: some_text, maxWidth: 200 });
More details here : Controlling the width of a Google Maps InfoWindow
Use as below in your google map script
//content = anything you like to show
var content = '<div id="content" align="center">'+
'<h1 id="firstHeading" class="firstHeading" style="margin:0;color:#ff6600;">Your Title</h1>'+
'<p style="color:#0d6585;font-weight:700;">Your Description'+
'</p>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: content,
maxWidth: 300 //your desired width
});
In infoWinfow options try to set maxWidth to 750. Also to make sure the style is not overwiten by default goole values rename google-infobox-content to something different. You may try to use a custom info window library:
http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobubble/examples/example.html
Make a div and set that to the infowindow using setcontent it works for sure

How to read Div inner contents at ajax?

I'm trying to update the sql db by a List of variables sent from the Html page.
Some of the Data are correctly sent, while others are not. I put the list in a div which is divided to two parts : "h1" and another "Div". The data at the header are all sent correctly, but the body itself which is at the second div isn't sent at all.
This is the Div which the data is put at:
$('#Classes').append('<div> <h1 class = "flip" wpID="' + subjects[i].Wkp_ID + '" lessonID="' + subjects[i].Ttb_lessonID + '" Date="' + Datecoming + '">' + subjects[i].sbj_Name + " Class:" + subjects[i].Ttb_Class + '</h1><div id ="NewBody" class="panel" contenteditable>' + subjects[i].Wkp_Body + '</div> </div>');
And that's how I read them at the ajax part:
var WeekPlan = [];
$('#Classes div').each(function (index) {
var header = $(this).children('h1');
var WeekBody = $(this).children('div').val();
var wpID = header.attr('wpID');
var lessonID = header.attr('lessonID');
var Wkp_Date = header.attr('Date');
WeekPlan[index] = { "Wkp_ID": wpID, "Wkp_Date": Wkp_Date, "Wkp_Body": WeekBody, "Wkp_lesson": lessonID };
});
The Wkp_ID, Wkp_Date, Wkp_Lesson are right, but the Wkp_Body just returns an empty string.
So do you know why is this happening and how can I truly read the body ? Most probably the problem is with this line:
var WeekBody = $(this).children('div').val();
But how can I access it correctly ?
Thanks a lot.
Here is what worked for me in case anyone needs it:
Creating the div:
$('#Classes').append('<div class="BigDiv"> <h1 class = "flip" wpID="'+ subjects[i].Wkp_ID + '" lessonID="' + subjects[i].Ttb_lessonID + '" Date="' + Datecoming + '">' + subjects[i].sbj_Name + " class:" + subjects[i].Cls_Name + '</h1><div class="panel" contenteditable>' + subjects[i].Wkp_Body + '</div> </div>');