PDA

View Full Version : Getting a Text Field to appear at a push of a button!


Big_Gee
07-28-2010, 12:06 PM
Hi All,

Please can somebody tell me how I can make a text field appear on a page when the user clicks on a button marked "Add" on a php page.

Thank you!
Big_Gee :lol:

davidj
07-28-2010, 12:56 PM
Are you wanting multiple text fields. A new one every time the button is clicked or just the one?

Big_Gee
07-28-2010, 04:08 PM
Hi,

A new filed everytime the button is pressed.

davidj
07-28-2010, 04:34 PM
<html>
<head>
<title></title>

<script language="javascript">

var fields = 1;
var maxfield = 4;

function addInput() {

if (fields <= maxfield) {

document.getElementById('text').innerHTML += "<input type='text' value='' name='field" + fields + "' /><br />";

fields += 1;

} else {

document.getElementById('text').innerHTML += "<br />Only "+ maxfield +" upload fields allowed.";

document.form.add.disabled=true;
}

}
</script>


</head>
<body>
<form name="form" method="post" action="">

<input type="button" onclick="addInput()" name="add" value="Add input field" />

</form>

<div id="text"></div>

</body>

</html>

Big_Gee
07-28-2010, 04:42 PM
Awesome!

Thanks alot!