Solved

align <input type="file"> with other page elements, uses javascriipt

Posted on 2011-03-01
4
534 Views
Last Modified: 2013-11-19
Hi, I have a page where rows are returned from a db.  The user can choose to add a new media field, which calls a javascript function.  This function displays a new row beneath the returned data rows from the db.

I am having difficulty getting it to line up correctly, with the Browse button and the Delete button.  Just need to get it tidied up a bit; that is all!  

Here is a snippet of the code inside the display portion of the page

 
<li id="row_9">
							<input type="hidden" name="type_9" value="text">
							<span class="txtbox1"><input type="text" name="name_9" value="CLINICAL AFFILIATION"></span>					
							<span class="txtbox1"><input type="text" name="value_9" size=60 value="Smith Northview Hospital?"></span> 
<input type="button" class="btn1" onClick="javascript:removeRow(9)"  value="Delete">
						</li>
						
						<li id="row_10">
							<input type="hidden" name="type_10" value="text">
							<span class="txtbox1"><input type="text" name="name_10" value="CLINICAL AFFILIATION"></span>					
							<span class="txtbox1"><input type="text" name="value_10" size=60 value="Tallahassee Community Hospital"></span> 
<input type="button" class="btn1" onClick="javascript:removeRow(10)"  value="Delete">
						</li>
						
						
							
				
					
				
             </div>
             <!--endeditoverview-->
 
	
       </div>
	<!--endmain-->
			
					
		<input type="hidden" id="maxFieldCount" name="maxFieldCount" value="10">
 
<div style="width: 100%; text-align: center">
	<input type="button" class="btn2" value="Add a New Text Field" onClick="addTextRow()"> 
&nbsp; &nbsp; &nbsp;
	<input type="button" class="btn2" value="Add a New Media Field" onClick="addMediaRow()">	    
<br/><br/>

Open in new window


Here is the javascript function which writes the row dynamically when the client clicks on the "Add a New Media Field" button.  


 
function addMediaRow() {
		var fieldCount = $('#maxFieldCount').val();
		++fieldCount;
		var newRowData = 	"<li id=\"row_"+fieldCount+"\">"+"<input type=\"hidden\" name=\"type_"+fieldCount+"\" value=\"media\">"+"<span class=\"txtbox1\"><input type=\"text\" name=\"name_"+fieldCount+"\" value=\"Field Name\"></span>"+"<span><input type=\"file\" name=\"value_"+fieldCount+"\" size=30 style=\"line-height: 14px\" value=\"Browse\"><input type=\"button\" class=\"btn1\" onClick=\"javascript:removeRow("+fieldCount+")\" value=\"Delete\"></span>"+"</li>";
		$('#row_'+(fieldCount-1)).after(newRowData);
		$('#maxFieldCount').val( fieldCount );
	}

Open in new window


And how it looks and how it should look:
 this is how it currently displays this is how I want it to look--or close to it style.css
0
Comment
Question by:trman
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
Shahzad Fateh Ali earned 500 total points
Comment Utility
Hi,

You have closed you <span/> after Delete button, close it just after file input. I  have attached the corrected code.
function addMediaRow() {
		var fieldCount = $('#maxFieldCount').val();
		++fieldCount;
		var newRowData = 	"<li id=\"row_"+fieldCount+"\">"+"<input type=\"hidden\" name=\"type_"+fieldCount+"\" value=\"media\">"+"<span class=\"txtbox1\"><input type=\"text\" name=\"name_"+fieldCount+"\" value=\"Field Name\"></span>"+"<span><input type=\"file\" name=\"value_"+fieldCount+"\" size=30 style=\"line-height: 14px\" value=\"Browse\"></span><input type=\"button\" class=\"btn1\" onClick=\"javascript:removeRow("+fieldCount+")\" value=\"Delete\">"+"</li>";
		$('#row_'+(fieldCount-1)).after(newRowData);
		$('#maxFieldCount').val( fieldCount );
	}

Open in new window

0
 
LVL 6

Expert Comment

by:hexer4u
Comment Utility
I would also suggest you do a CSS hack to get rid of that UGLY browse button and replace it with something nicer.

Basically inside a wrapper <div> you add the <input type="file">, and set the opacity of the input to 0, and the background of the wrapper to be like a button. That way the user will still click the input but will think he's clicking the button (which is not there)
0
 

Author Comment

by:trman
Comment Utility
hi shahzadfatehali:

I tried the code you suggested. In FF it almost works, but the Delete button covers the Browse button part way. In IE, the Delete button shows up, but no sign of the Browse button or field where the file goes.

Any thoughts??
0
 
LVL 9

Expert Comment

by:Shahzad Fateh Ali
Comment Utility
Well in your case you can easily rid of it using div based columns structure inside <li />
like

<li><div>Column 1<div><div> Column 2</div>.....</li>
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now