[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-03-01
4
Medium Priority
?
565 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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
Suggested Courses

873 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