/    Sign up×
Community /Pin to ProfileBookmark

form submit causes page to reload

Hi guys,

Busy day today, third post so far.
In my form I used to have a button to submit the form. Now I’ve changed it to an image and it causes my page to reload. Any suggestions?

<script>
function checkField(){
if(document.searchMenu.searchStr.value == “”){
alert(‘Please enter menu to search for!’);
return 0;
}
str = document.searchMenu.searchStr.value;
document.all.helpiframe.src=”smm3.jsp?searchStr=” + str;
showHide(‘passwordLayer’,’visible’);
}
</script>

<form method=”POST” name=”searchMenu” onSubmit=”checkField()”>

<input type=”image”
src=”searchButton.gif”
valign=”bottom”
font face=”arial”
size=”10″>

thanks,
webtekie

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@pyroAug 19.2003 — Try changing your onsubmit tag to look like this:

onsubmit="checkField(); return false;"

or

onsubmit="return checkField()"

and add return false to the bottom of your checkField function.
Copy linkTweet thisAlerts:
@webtekieauthorAug 19.2003 — thanks pyro, that did it.
Copy linkTweet thisAlerts:
@pyroAug 19.2003 — You're welcome... ?
×

Success!

Help @webtekie spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...