<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Dynamically add Textbox, Radio, Button in html Form using Javascript</title> <script language="javascript"> function add(type) { //Create an input type dynamically. var element = document.createElement("input"); //Assign different attributes to the element. element.setAttribute("type", type); element.setAttribute("value", type); element.setAttribute("name", type); var foo = document.getElementById("fooBar"); //Append the element in page (in span). foo.appendChild(element); } </SCRIPT> </head> <body> <FORM> <H2>Dynamically add element in form.</H2> Select the element and hit Add to add it in form. <BR/> <SELECT name="element"> <OPTION value="button">Button</OPTION> <OPTION value="text">Textbox</OPTION> <OPTION value="radio">Radio</OPTION> </SELECT> <INPUT type="button" value="Add" onclick="add(document.forms[0].element.value)"/> <span id="fooBar"> </span> </FORM> </body>
new to php
Page 1 of 19 Replies - 1201 Views - Last Post: 19 January 2013 - 07:21 PM
#1
new to php
Posted 19 January 2013 - 04:56 AM
hi im new to php and i searched this code that adds elements to m program and i can't seem to access the code when i open it on my browser on localhost/(myfile) here is my code:
Replies To: new to php
#2
Re: new to php
Posted 19 January 2013 - 05:32 AM
Don't be a copy/paste programmer and you won't have these types of problems!
- There is no PHP code in what you've shown.
- You can't access PHP code from a browser because PHP is processed on the server.
#3
Re: new to php
Posted 19 January 2013 - 06:58 AM
CTphpnwb, on 19 January 2013 - 05:32 AM, said:
Don't be a copy/paste programmer and you won't have these types of problems!
- There is no PHP code in what you've shown.
- You can't access PHP code from a browser because PHP is processed on the server.
i already figure it out sir thanks

but i have another question is it possible to save the elements as it is added the way i want it to look?
#5
Re: new to php
Posted 19 January 2013 - 12:35 PM
#7
#8
Re: new to php
Posted 19 January 2013 - 06:19 PM
You are not going to learn how to program and make things by copy and pasting code. It's common sense. Will you learn the contents of a test if you copy off another person? No.
Learn PHP and naturally you will learn how to solve problems you have. If for whatever reason you don't want to do that, you can hire someone to do it for you.
Learn PHP and naturally you will learn how to solve problems you have. If for whatever reason you don't want to do that, you can hire someone to do it for you.
#9
Re: new to php
Posted 19 January 2013 - 06:47 PM
creativecoding, on 19 January 2013 - 06:19 PM, said:
You are not going to learn how to program and make things by copy and pasting code. It's common sense. Will you learn the contents of a test if you copy off another person? No.
Learn PHP and naturally you will learn how to solve problems you have. If for whatever reason you don't want to do that, you can hire someone to do it for you.
Learn PHP and naturally you will learn how to solve problems you have. If for whatever reason you don't want to do that, you can hire someone to do it for you.
ok sir thanks for the advise but one last question am I learning the right programming language because i read the code and its javascript i think but its working
#10
Re: new to php
Posted 19 January 2013 - 07:21 PM
yes the code you posted is javascript.
Javascript is ran on the "clients" side. Meaning it is ran on your user's computer when they go to your website. It can do things like manipulate forms (like you did above).
PHP is ran on the "server" side. Meaning it is ran on your computer hosting the website. It can do things like store information.
Javascript is ran on the "clients" side. Meaning it is ran on your user's computer when they go to your website. It can do things like manipulate forms (like you did above).
PHP is ran on the "server" side. Meaning it is ran on your computer hosting the website. It can do things like store information.
Page 1 of 1