Jump to content

how to collect data from a form tag, e.g an <input type='text">


Recommended Posts

There are things Javascript just can't do. If you want to be a web developer you have to learn all the necessary technologies.

 

Javascript can manipulate objects on the page, including form elements, but it cannot save the data onto the server. A server-side language is required for that.

 

This example will show you how to read the data from a form field in Javascript:

http://www.w3schools.com/js/js_validation.asp

 

You can save the data you read into a cookie or localstorage, but you will not be able to access that data from any other computer than the user's own computer.

  • Like 1
Link to post
Share on other sites
  • 4 weeks later...

Hi I am having challange as regard how to get the click value of Navigaion elements like "Home" "About" "Contact" etc. what i mean how to write appropriate codes for the HTML and CSS so that once one clicks on any of them the appropriate value is displayed or one get to the link. i know it is to be done using DOm put dont know how yet. can you help me or get me to someone who wouyld. thanks

Link to post
Share on other sites

Maybe something like this?

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"/><title>title</title><style>[type=button]{margin:10px 0}#out{width:200px;border:1px solid #ccc;}</style><script>window.onerror = function(a, b, c, d){alert('Javascript Error:n'+a+'nURL: '+b+'nLine: '+c+'  Column: '+d);return true;}</script><script>'use strict';window.onload = init;function init() { document.getElementById('btnHome').onclick = fnHome; document.getElementById('btnAbout').onclick = fnAbout; document.getElementById('btnContact').onclick = fnContact; document.getElementById('btnClear').onclick = fnClear;}function fnHome(){ alert('Home was clicked');}function fnAbout(){ var str = "<h3>Values:</h3>"; str += document.getElementById('name').placeholder + " = "; str += document.getElementById('name').value + "<br/>"; str += document.getElementById('street').placeholder + " = "; str += document.getElementById('street').value + "<br/>"; str += document.getElementById('city').placeholder + " = "; str += document.getElementById('city').value + "<br/>"; str += document.getElementById('state').placeholder + " = "; str += document.getElementById('state').value + "<br/>"; document.getElementById('out').innerHTML = str;}function fnContact(){ alert('Contact was clicked');}function fnClear(){ var list = document.getElementsByTagName('INPUT'); for (var i=0 ; i<list.length ; i++){  if (list[i].type=='text'){    list[i].value = "";  } } document.getElementById('out').innerHTML = "";}</script></head><body><h3>Information:</h3><input type="text" id="name" placeholder="Name"/><input type="text" id="street" placeholder="Street"/><br/><input type="text" id="city" placeholder="City"/><input type="text" id="state" placeholder="State"/><br/><input type="button" id="btnHome" value="Home"><input type="button" id="btnAbout" value="About"><input type="button" id="btnContact" value="Contact"><input type="button" id="btnClear" value="Clear"><div id="out"></div></body>    </html>
Link to post
Share on other sites

I'm having this problem :facepalm:

..the problem you are showing is a headache

 

first on the html file you need this : <form method="post" action="results.php" onsubmit="">

<input type="text" name="name" required >

 

 

then on results you need that $name = $_POST["name"];

 

Those two files communicate via a server eg Apache. You have to install one

Link to post
Share on other sites

..the problem you are showing is a headache

 

first on the html file you need this : <form method="post" action="results.php" onsubmit="">

<input type="text" name="name" required >

 

 

then on results you need that $name = $_POST["name"];

 

Those two files communicate via a server eg Apache. You have to install one

Why do you have an empty onsubmit attribute on your <form> element?

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...