Solved

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

Posted on 2011-03-01
4
545 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
ID: 35014869
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
ID: 35016671
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
ID: 35018090
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
ID: 35024581
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CSS Style on Chrome 1 40
modify change color of text 9 39
HTML editor custom button 3 60
Can anyone help me find this preloader? 51 48
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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 a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

730 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