473,544 Members | 713 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

POST and Javascript

2 New Member
<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 7563
sashi
1,754 Recognized Expert Top Contributor
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 Recognized Expert Top Contributor
<script>
function validateform() {
tmpname = document.getEle mentById('fname ');
if (tmpname=="") {
alert('You didn't fill out the first name field');
} else {
document.insert form.submit();
}
}
</script>
<form action="insert_ contact.php" method="POST" name="insertfor m">
Firstname
<input type="text" maxlength=30 name="fname" id="fname">
<input type="button" value="insert" onclick="valida teform();">
</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
janjan_376
2 New Member
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 Recognized Expert Top Contributor
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
4248
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 second form when it is called. Both forms are .htm files that call themselves when the submit button is press via the following command in each form:...
5
16587
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. Thanks in advance for any inputs or ideas,
3
3245
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 method=post action=RegDetails.asp> I have tried to modify the form by adding javascript for password
5
2149
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 have FormValidate Javascript function postback to my addToCart Method in my code behind function ValidateForm(myform) { if...
2
12537
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 <form action="display.aspx" method="post" target="_blank"> will submit the form data and open display.asp in a new browser
3
2059
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 program a javascript routine called sorttable.js which is something I found on the internet for sorting tables and works quite well. The HTML...
2
2032
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 javascript is enabled, I auto-post the form at the bottom of the .aspx page. It works fine. With javascript disabled, however, the action of the form,...
1
1555
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 subsequently, no post- back occured (because the index of the selected item did not change, hence the click event was not captured). So, to capture the click...
2
6798
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 subsequently, no post- back occured (because the index of the selected item did not change, hence the click event was not captured). So, to capture the click...
56
7180
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 website. The issue is that I need to gauge whether a user has any items in their basket to decide which page I redirect them too. I could
0
7439
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7633
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7785
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7722
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5935
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4932
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3433
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3425
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1851
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.