473,404 Members | 2,195 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

How to display form input on the same page using Javascript?

I would like to display the details of all the Input fileds entered by user back in the same page. is it possible? if so, i would also like to alert user not to keep the field empty.
Jan 27 '11 #1
2 1300
I'm not a 100% sure what you want but I think this is what you want:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function formcheck(){
  5.     var blankfields = new Array()
  6.     if(document.getElementById("country").value == "Country"||document.getElementById("country").value == ""){
  7.         blankfields.push("Country")
  8.     }
  9.     if(document.getElementById("email").value == "Email"||document.getElementById("email").value == ""){
  10.         blankfields.push("Email")
  11.     }
  12.     if(blankfields == ""){
  13.         alert("Thank You For Filling Out Our Survey!")
  14.     }
  15.     else{
  16.         blankfieldsjn = blankfields.join("\n")
  17.         alert("You need to fill out the following fields before proceeding:" + "\n" + blankfieldsjn)
  18.     }
  19. }
  20. </script>
  21. </head>
  22. <body>
  23. <form>
  24. <input id="country" type=text value="Country"><br />
  25. <input id="email" type=text value="Email"><br />
  26. <input type=button value="Submit" onClick=formcheck()>
  27. </form
  28. </body>
  29. </html>
Jan 27 '11 #2
Dear Mad Genius,

Below is my code. I would like to alert the user not to keep any field blank and the cursor should point to the field where the user is trying to skip the field when he presses enter key or submit key.

Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2.   <HEAD>
  3.     <TITLE>Basic Details</TITLE>
  4.  
  5.     <script type="text/javascript">
  6.       function details()
  7.       {
  8.         var name1 = document.myform.name.value;
  9.     if (name1.length === 0) {
  10.     alert("You must enter your Name ");
  11.     return false;
  12.      }
  13.  
  14.     var age1 = document.myform.age.value;
  15.     if (age1.length === 0) {
  16.     alert("You must enter your Age ");
  17.     return false;
  18.      }
  19.  
  20.     var city1 = document.myform.city.value;    
  21.         if (city1.length === 0) {
  22.     alert("You must enter your City ");
  23.     return false;
  24.      }
  25.  
  26.     document.getElementById("divid1").innerHTML = name1;
  27.     document.getElementById("divid2").innerHTML = age1;
  28.     document.getElementById("divid3").innerHTML = city1;
  29.  
  30.     return true;
  31.  
  32.     }
  33.     </script>
  34.  
  35.   </HEAD>
  36.  
  37.   <BODY>
  38.  
  39.     <FORM NAME="myform">
  40. Enter your name: <BR>
  41.       <INPUT TYPE="text" NAME="name" VALUE="" onClick="details();"><BR>
  42. Enter your age: <BR>
  43.       <INPUT TYPE="text" NAME="age" VALUE="" onClick="details();"><BR>
  44. Enter your city:<BR>
  45.       <INPUT TYPE="text" NAME="city" VALUE="" onClick="details();"><P> 
  46.       <INPUT TYPE="button" Value="Submit" onClick="details()">
  47.     <INPUT TYPE="reset" VALUE="Reset">
  48.     </FORM>
  49.  
  50. You have entered the following details:
  51. <P>
  52. Your Name is: <span id="divid1"></span><P>
  53. Your Age is: <span id="divid2"></span><P>
  54. Your City is: <span id="divid3"></span>
  55.  
  56. </BODY>
  57. </HTML>
Jan 27 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Tony Strazzeri | last post by:
Hi, I recently posted "problem with Javascript code from Include" Thanks to response I have now fixed the problem. This is to ask how to solve my next problem/step. I am using javascript to...
1
by: keerthana_m_2003 | last post by:
Hello: I am designing a web page where there are some buttons text etc. I want to design it in such a way that, irrespective of the screen size, resolutoin; the buttons will have to come always...
14
by: Sofia | last post by:
Hi there is text field and a button.... now i have to send this textfield value to another page without using form tag......i have to use javescript... is there anyone who can help me regarding...
2
by: simon.wilkinson | last post by:
Hi, I am trying to update all Select boxes on a page dynamically using javascript, I simple want to change the selected item in each select box when a tick box is pressed on the page. Each...
1
by: ruchinagaich1 | last post by:
Please tell me, How do i open a hyperlink in parent page using javascript?
7
by: vunet.us | last post by:
Can I get the name of a referral page using JavaScript? Just really wondering...
3
by: akristensen | last post by:
I am new to this site, so be patient if I do not ask the question correctly. Current Target Platform: Browser: MS IE, script language: Javascript (will use VBScript, but JS is preferred), External...
1
by: fastvarun | last post by:
Can anybody help me how to remove url while print out of a page using javascript window.print() plz help me...........................
28
by: macca | last post by:
Hi, I'm developing an application that is going to be used in schools as a teaching aid and require the ability to temporarily draw on my (as in pages produced by my application) web page using...
4
Ashwani Sharma
by: Ashwani Sharma | last post by:
is there any way to save a web page using javascript in cross browser
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.