473,324 Members | 2,473 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,324 software developers and data experts.

POST and Javascript

<form action="insert_contact.php" method="POST">
Firstname
<input type="text" maxlength=30 name="fname">
<input type="submit" value="insert">
</form>
</body>
</html>

----------------------------------------------------------------------------

for the above HTML script, is there a way I could pass the variable fname to a javascript before it passes to PHP. I want javascript to check if there is a data on that field when 'insert' button is clicked, if not then cursor will go automatically back to the box or a perhaps a message will appear. And if there is data, javascript will just exit and give the rest of the procedure to PHP. Is that possible? Please help
Jul 12 '06 #1
4 7557
sashi
1,754 Expert 1GB
Hi there,

well.. yeah sure.. let do client side validation here.. ok

write a js fucntion to validate the contents of the "fname" field.. invoke the function on the OnSubmit event.. good luck my fren.. :)

come up with the js code first.. we will help you to validate your code..
Jul 12 '06 #2
iam_clint
1,208 Expert 1GB
<script>
function validateform() {
tmpname = document.getElementById('fname');
if (tmpname=="") {
alert('You didn't fill out the first name field');
} else {
document.insertform.submit();
}
}
</script>
<form action="insert_contact.php" method="POST" name="insertform">
Firstname
<input type="text" maxlength=30 name="fname" id="fname">
<input type="button" value="insert" onclick="validateform();">
</form>

</body>
</html>

You can also look up javascript setting focus by id on google to set the text field as the focus.
Jul 14 '06 #3
Hi,
first of all thank you for responding and thank you for your time, however, it did not work. I noticed that there is missing <html> tag so I put it on the very top part of the script and the <body> right below the </script> but still no luck. please help
Jul 16 '06 #4
iam_clint
1,208 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <script>
  4. function validateform() {
  5. var tmpname = document.getElementById("fname").value;
  6.     if (tmpname=="") {
  7.         alert("You didn't fill out the first name field");
  8.     } else {
  9.         document.insertform.submit();
  10.     }
  11. }
  12. </script>
  13. <form action="insert_contact.php" method="POST" name="insertform">
  14. Firstname
  15. <input type="text" maxlength=30 name="fname" id="fname">
  16. <input type="button" value="insert" onclick="validateform();">
  17. </form>
  18. </body>
  19. </html>
  20.  
my bad janjan -- this works as you can see i had to change a couple things i wasn't thinking completely and didn't test it before i posted it for you, the get element by id needed to have .value on it and the single quotes needed changed to double quote " this should work for you
Jul 16 '06 #5

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

Similar topics

5
by: TG | last post by:
Dear PHP Group, I have two forms that are used to collect user information. The first one takes user inputted values such as fullname, city, address etc. I want these values to display in the...
5
by: Earth | last post by:
Hi all, I am new in javascript. And I would like to find out whether window.open use GET or POST. I have tried to find the FAQ but no finding. Please enlighten me or direct me to any FAQ. ...
3
by: iam247 | last post by:
Hi I have an asp page without any javascript. It posts the content of a form to another page, which reads the form fields using Request.Form. This is the form header: <form name=form...
5
by: Gary Vidal | last post by:
I have a client side Javascript which checks an OrderQuantityField against a hidden Textbox of the Minimum Order Quantity. I dont want to do validation on a postback. I would like to be able to...
2
by: Matt | last post by:
When we submit the form data to another page, we usually do the following: <form action="display.aspx" method="post"> will submit the form data and open display.asp in the current browser ...
3
by: Vic Spainhower | last post by:
Hello, I have an HTML table that is being constructed from a MySQL table and displays a form that includes a check box on 1 of the fields on the form for each record. I have included in this PHP...
2
by: scotty | last post by:
I have a ListBox with AutoPostBack='True'. The corresponsing form is set as follows: <form runat='server' method='POST' action='results.asp' name='mbrlst_search' ID='search_form'> When...
1
by: Garg | last post by:
I had a listbox, whose autoPostBAck property was set to true. So. if I was clicking on any item for the first time, it caused a successful post-back. However, if i clicked on the item...
2
by: Garg | last post by:
I had a listbox, whose autoPostBAck property was set to true. So. if I was clicking on any item for the first time, it caused a successful post-back. However, if i clicked on the item...
56
by: UKuser | last post by:
Hi, I'm not sure if this can be done as I've searched the web and this forum. I am using an online merchant provider and I must post certain variables to their webforms through a form on my...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.