473,382 Members | 1,367 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,382 software developers and data experts.

Same function different results...

If you invoke the "check_link" function using the "Go" link than
everything works as I expect.
If invoking it using the Submit button than the text field value shows
the new value ("Executed Link") for a split second and than reverts
back to the default value.

Why?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Untitled Document</title>

<script type="text/javascript" language="javascript">
function check_link()
{ var new_link=document.getElementById('fName').value;
var newwin = window.open(new_link, "temp_win");
document.getElementById('fName').value='Executed Link';
}
</script>

</head><body>
<form name="form1" method="post" action="">
<input name="fName" type="text" id="fName" value="http://google.net">
<a href="javascript:check_link()">Go</a><br>
<input name="Submit" type="submit" onClick="check_link();"
value="Submit">
</form>
</body>
</html>

Aug 14 '05 #1
2 1374


danarz@ wrote:

If invoking it using the Submit button than the text field value shows
the new value ("Executed Link") for a split second and than reverts
back to the default value.


As the submit button submits the form the action URL is being requested
by the browser, with action="" the browser submits to the page itself.
If you do not want to submit the form data then don't use a submit button.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 14 '05 #2
Lee
danarz@ said:

If you invoke the "check_link" function using the "Go" link than
everything works as I expect.
If invoking it using the Submit button than the text field value shows
the new value ("Executed Link") for a split second and than reverts
back to the default value.

Why?


Because the submit button submits the form.

With no action specified, submitting the form causes the page to reload.
Don't use the onClick event handler of a submit button.
Don't use a submit button at all, if you don't really want to submit a form.

Aug 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Thomas Mlynarczyk | last post by:
While experimenting with Array.sort(function) I got different results from different browsers. How can that be? Shouldn't I expect identical results - given both the input array and the sort...
6
by: CJ | last post by:
Okay, same program, different issue. Thanks to the help that I was given I was able to complete my program to find variables in a list that were repeated, and display them once, and how many times...
8
by: Ravindranath Gummadidala | last post by:
Hi All: I am trying to understand the C function call mechanism. Please bear with me as I state what I know: "every invocation of a function causes a frame for that function to be pushed on...
15
by: Mike Lansdaal | last post by:
I came across a reference on a web site (http://www.personalmicrocosms.com/html/dotnettips.html#richtextbox_lines ) that said to speed up access to a rich text box's lines that you needed to use a...
33
by: genc_ymeri | last post by:
Hi over there, Propably this subject is discussed over and over several times. I did google it too but I was a little bit surprised what I read on internet when it comes 'when to use what'. Most...
0
by: Darrel | last post by:
I've been having problems trying to delete a file. I can upload and save the file no problem, but deleting it gives me two results: If I run the delete function from my app's unprotected (public)...
18
by: MajorSetback | last post by:
I am using the Redhat version of Linux and GNU C++. It is not clear to me whether this is a Linux issue or a C++ issue. I do not have this problem running the same program on Windows but...
7
by: john_smith_1221 | last post by:
Hello, I need to use the rand() function to generate a random value, I already know how to do it with srand(time(NULL)) and its "randomness" is sufficient for me, the problem is my code requires to...
45
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4. An odd thing is happening with the mcrypt_encrypt function. I am trying to encrypt a string of data (for password storage): $enc = mcrypt_encrypt(MCRYPT_XTEA,...
5
by: Christopher Brewster | last post by:
I am running the same script on the same data on two different machines (the folder is synchronised with Dropbox). I get two different results. All the script does is count words in different...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.