Solved

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

Posted on 2011-03-01
4
549 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
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…

705 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