Solved

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

Posted on 2011-03-01
4
537 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Close "X" button on window popup in Firefox 7 34
Remove greater than sign 3 41
Error on Add method 1 37
Change CSS to show Notification Bar 9 11
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
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 …
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

929 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

11 Experts available now in Live!

Get 1:1 Help Now