Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Page reloading problem

 
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,
I'm having strange problem here. With the below mentioned code if the enter some value in the text box and hit ENTER key the page is reloading automatically with query string. If I enter 323232 in the text field and hit enter the page reloads with url
temp5.asp?text1=323232. What could be the problem ? I don't want anything to happen if I press enter key. How to fix it ?
Thanks
temp5.asp
<%@ Language=VBScript %>

<script language="Javascript">

function validateData() {
if (document.form1.text1.value == "") {
alert("Please enter Number.");
return;
}
document.form1.action="Validate.asp";
document.form1.method="post";
document.form1.submit();
}

</script>
<html>
<head> </head>
<body>

<form name=form1>
<table align=center>
<tr>
<td> Number </td>
<td> <input type="text" maxlength="20" size=30 name="text1" id="text1"> </td>
</tr>
</table>
<input type="button" value="GO" onclick="validateData()" id=button1 name=button1>
</form>
</body>
</html>
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
add action="" in form tag, like this:
<form name=form1 action="">
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hitting enter is pressing your button, which is firing you script, which is submitting your form. To confirm this, you could pop an alert inside the script. You could disable the button until you are ready for it. You could perform some sort of test before submitting the form in your script. There are a bunch of solutions depending on what you are trying to accomplish.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that the Javascript is not finding the Validate.asp page. It is creating a new temp page. With temp5.asp would seem that you have tried this 5 times. I would suggest reviewing the documentation on javacript. Using javascript for forms is complex. I always recommend that you use the action and method in the form tag.
This is only a suggestion.
[This message has been edited by R Hunter (edited August 22, 2001).]
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic